行を合計し、最後の列に合計を入れる必要がある出席スプレッドシートがあります。各行は従業員を表し、各列はその月の日を表します。私が VBA を使用している理由は、一部の日付列にテキスト (Tardy の TA など) が含まれ、TA が範囲内の 1 つ以上のセルに存在する場合は合計に 0.5 を追加する必要があるためです。
最初の行にのみ入力できますが、その下の行には入力できません。範囲を正しく設定していないためだと思います。これが私がこれまでに持っているコードです:
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
For Each ループの周りで For i = 1 To LastRow Step 1 を使用してみても、成功せずに Do.....Loop until LastRow を使用しました。私の行は常に行3から始まるので、次の行に沿って何かが必要です:
AG3 =SUM(B3:AF3)
AG4 =SUM(B4:AF4)
最後の行まで