PDA

View Full Version : [SOLVED] VBA to sum data on another worksheet



msquared99
05-06-2015, 12:08 PM
OK, I know this is simple but I am not getting it.

All I want to do is sum the data in column H on the WSIC worksheet in the WSCS worksheet.

So cell B3 in the WSCS will have a formula in it and not a value.


Sub Macro1()
Dim WSIC As Worksheet, WSM3 As Worksheet, WSCS As Worksheet
Dim LastRow As Long
Set WSIC = Worksheets("IC")
Set WSM3 = Worksheets("M3")
Set WSCS = Worksheets("Commission Summary")
With WSIC
LastRow = Cells(.Cells.Rows.Count, "H").End(xlUp).Row - 1
End With
With WSCS
.Range("B3") = "=sum(H2:H" & LastRow & ")"
'=== I want this line of code to sum column H on WSIC
End With
MsgBox LastRow
End Sub


Thanks for your help.

msquared99
05-06-2015, 12:26 PM
Never mind I got it. My issue was I did not Reset the macro to clear the LastRow value.

BTW this line of code worked:


WSCS.Range("B3") = "=Sum(IC!H2:H" & LastRow & ")"