As I’m just starting out with coding excel, I’m starting to notice that I use a lot of activecell.offset commands to navigate around my spreadsheets. Is this normal? Or are there more efficient ways to do this?
Here is an example of some code I have done, it works so I’m happy but I’m interested to learn if there are other methods being used by more advanced programmers.
Sub Totals3()
Dim dSub5 As Double
Dim dSub6 As Double
Range(“AF1”).Select
Do Until ActiveCell.Offset(0, -30).Value = “TOTAL – COST OF GOODS SOLD”
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = “PST” Then
dSub5 = ActiveCell.Offset(0, -7) + dSub5
dSub6 = ActiveCell.Offset(0, -4) + dSub6
Else
End If
Loop
ActiveCell.Offset(0, -7).Value = dSub5
ActiveCell.Offset(0, -4).Value = dSub6
ActiveCell.Offset(0, -3).Value = dSub5 – dSub6
ActiveCell.Value = “PSGT”
ActiveCell.Offset(0, -7).Range(“A1:H1”).Select
With Selection.Interior
.ColorIndex = 6
End With
Selection.Font.Bold = True
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
End With
End Sub
Kind regards
Hayden