Math
Math

Reputation: 1294

offset with column=-1 in VBA

I'm trying to find a solution to the problem when selecting a column =-1 first I select the cell A1, and then I apply this code.

 Sub exc()
ActiveCell.Offset(-1, 0).Select
If .Offset(-1, 0).Row < 1 Then
ActiveCell.Offset(1, 0).Select
End If
End Sub

But problem not solved.

Thank you for help.

Upvotes: 0

Views: 259

Answers (1)

Scott Craner
Scott Craner

Reputation: 152585

You need to test before doing the offset:

Sub exc()
IF Activecell.Row > 1 then
     ActiveCell.Offset(-1, 0).Select
Else
    ActiveCell.Offset(1, 0).Select
End If
End Sub

Upvotes: 1

Related Questions