Here are 3 worksheets.
'//i.stack.imgur.com/KeULk.png
' //i.stack.imgur.com/w9wa7.png
' //i.stack.imgur.com/KLeUl.png
Case:
I want to sum the days for each person. The result is displayed on worksheet-report.
The days store in worksheet-day. The day is not fixed. The range of the days should be according to
row: that person row in worksheet-day
column :Worksheets("button").Cells(1, 2 ) to Worksheets("button").Cells(2, 2)
Here is my code:
Sub gg()
row = Worksheets("report").Range("C" & Rows.Count).End(xlUp).row
Row2 = Worksheets("day").Range("C" & Rows.Count).End(xlUp).row
Dim g As Range 'the range for sum
Dim row999 As Integer 'store the selected row index
For k = 2 To Row2 'check and store appropriate row
If Worksheets("report").Cells(1, k).Value = Worksheets("day").Cells(1, k).Value Then
row999 = ActiveCell.row
End If
Next k
g = Range(Cells(Worksheets("button").Cells(1, 2), row999), Cells(Worksheets("button").Cells(2, 2), row999))
For j = 2 To row 'do the sum
Worksheets("report").Cells(2, i) = Application.WorksheetFunction.Sum(g)
Next j
End Sub
I guess the g is inaccurate here.
g = Range(Cells(Worksheets("button").Cells(1, 2), row999), Cells(Worksheets("button").Cells(2, 2), row999))
