In Excel I have a button that moves the selected cell marker up the page by 20 places relative to the cell that you were originally on. It works fine until it gets to the top and then has an error.
I get that this is [most likely] due to it going out of range, so I tried to make an if else statement to solve it – I think because I’m not 100% familiar with the function names I can’t find the right wording to say:
if cell is out of range, make equal to 0,0 or something similar.
This is what I have so far; the only bit that does work is the else part of the statement:
Sub moveUp20()
'
' Move Up 20 Macro
'
'
If ActiveCell.Offset(-20, 0) <= Range(0, 0) Then
ActiveCell.Select = Range(0, 0)
Else
ActiveCell.Offset(-20, 0).Select
End If
End Sub
It is probably something simple as I’m not familiar with excel macro programming terms/semantics, so I would appreciate some help! Thanks! 🙂
1 Answer