G
Guest
Can some please check this code and tell me what I'm doing wrong? The idea
is to go down the E column and check for the code 'AJ'. Then, when it
reaches the empty row, it should insert the SUM function 2 columns over (G)
and total everything from E3 to the end of the data. This data will be
imported and will vary in length.
Set TestRng = Range("E3")
If TestRng.Value = "AJ" Then
Do Until TestRng.Value <> "AJ"
Set TestRng = TestRng.Offset(1, 0)
Loop
End If
ThisWorkbook.Names.Add Name:="AjEnd", _
RefersTo:="=$E$3:TestRng", Visible:=False
TestRng.Offset(0, 2).Value =
Application.WorksheetFunction.Sum(AjEnd.Offset(0, 2))
is to go down the E column and check for the code 'AJ'. Then, when it
reaches the empty row, it should insert the SUM function 2 columns over (G)
and total everything from E3 to the end of the data. This data will be
imported and will vary in length.
Set TestRng = Range("E3")
If TestRng.Value = "AJ" Then
Do Until TestRng.Value <> "AJ"
Set TestRng = TestRng.Offset(1, 0)
Loop
End If
ThisWorkbook.Names.Add Name:="AjEnd", _
RefersTo:="=$E$3:TestRng", Visible:=False
TestRng.Offset(0, 2).Value =
Application.WorksheetFunction.Sum(AjEnd.Offset(0, 2))