Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:33:43+00:00 2026-06-17T23:33:43+00:00

I have an Attendance spreadsheet where I need to SUM a row and have

  • 0

I have an Attendance spreadsheet where I need to SUM a row and have the totals in the last columns. Each row represents an employee and each column represents a day in the month. The reason I am using VBA is because some date columns will contain text, such as TA for Tardy and need to add 0.5 to the total if TA is present in one or more of the cells in the range.

I can only get the first row to populate, but not the rows below it. I am guessing it is because I am not setting my ranges correctly. Here is the code that I have so far:

Dim wsJAN As Worksheet      'Used to reference the sheet by its TAB name in the WB
Dim LastRow As Long         'Last used row on sheet
Dim tDays As Range          'Total # of days the employee has actually worked
Dim cDays As Range          'Current # of days the employee should have worked
Dim rowEmployee As Range    'Used to define the columns to be used to when adding attendance for each employee row
Dim rCell As Range

LastRow = Cells.Find(What:="*", After:=[A3], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

Application.ScreenUpdating = False

Set wsJAN = ThisWorkbook.Sheets("JAN")
Set tDays = wsJAN.Range("AG3")
Set cDays = wsJAN.Range("AH3")
Set rowEmployee = wsJAN.Range("B3:AF3")

tDays = "=SUM(B3:AF3)"
cDays = "=SUM(B3:AF3)"

For Each rCell In rowEmployee
If rCell.Value = "TA" Then

    tDays = tDays + 0.5    ' Add only a half day to the # of days the employee has worked in Column AG if tardy.
    cDays = cDays + 1      ' Add a whole day to current days worked in Column AH if employee is tardy.
End If
Next


Application.ScreenUpdating = True

I have even tried using For i = 1 To LastRow Step 1 around the For Each loop and Do…..Loop Until LastRow with out any success. My rows will always start at row 3 so I need something along the lines of :

AG3 =SUM(B3:AF3)
AG4 =SUM(B4:AF4)

Down to the last row

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:33:44+00:00Added an answer on June 17, 2026 at 11:33 pm

    You should be using two loops instead of one – to sum in cols and in rows. For me the easiest way to run through such a regular sheet is to use Offset for the given range. Here’s the solution:

    Dim wsJAN As Worksheet      'Used to reference the sheet by its TAB name in the WB
    Dim LastRow As Long         'Last used row on sheet
    Dim tDays As Double          'Total # of days the employee has actually worked
    Dim cDays As Integer          'Current # of days the employee should have worked
    Dim rowEmployee As Range    'Used to define the columns to be used to when adding attendance for each employee row
    Dim rCell As Range
    Dim i As Integer
    
    Application.ScreenUpdating = False
    
    Set wsJAN = ThisWorkbook.Sheets("JAN")
    Set rowEmployee = wsJAN.Range("B3:AF3")
    
    i = 0
    Do While Range("B3").Offset(i).Value <> Empty        ' for each row
        tDays = 0
        cDays = 0
        For Each rCell In rowEmployee          ' for each column
            If rCell.Offset(i).Value = "TA" Then
                tDays = tDays + 0.5    ' Add only a half day to the # of days the employee has worked in Column AG if tardy.
                cDays = cDays + 1      ' Add a whole day to current days worked in Column AH if employee is tardy.
            End If
        Next
        ' set AG as tDays && AH as cDays
        Range("AG3").Offset(i).Value = tDays
        Range("AH3").Offset(i).Value = cDays
        i = i + 1
    Loop
    
    Application.ScreenUpdating = True
    

    Now it counts the TA-s only (your IF statement says so), but you can now easily modify it, to count whatever is needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some attendance software. Each member will have an ID card with a
Here the question, I have a table called attendance with 4 columns: [Username] varchar(256)
I have two Model classes: Attendance and Employee. I have defined the Employee class
I have employees attendance table from date 1 to 31 with column names like
I have two arrays: 1. each object here is a row retrived from database.
I have a table of students and in each row are their names, a
I have a table that tracks attendance in a course. The columns are the
I have two bit type columns in my sql table for the staff attendance,
I have a table full of attendance data for students, we are migrating to
I have an Attendance model that allows the user to enter a starting, ending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.