Reading location of active cell

  • Thread starter Thread starter Dean
  • Start date Start date
D

Dean

Hello,
For my project I am making on excel, I need to move the selected cell
up so for example if I click on A2 then A1 would be selected
Is this possible,
Thanks
 
ActiveCell.Offset(-1,0).select

If the cursor is in row 1 when you try to do this command you will recieve
an error, To avoid this you can do so:

If ActiveCell.Row>1 then
ActiveCell.Offset(-1,0).select
End If

Hopes this helps.
 
ActiveCell.Offset(-1,0).select

If the cursor is in row 1 when you try to do this command you will recieve
an error, To avoid this you can do so:

If ActiveCell.Row>1 then
    ActiveCell.Offset(-1,0).select
End If

Hopes this helps.

---
Per

"Dean" <[email protected]> skrev i meddelelsen



- Show quoted text -

Hey thanks for your reply,
but what I meant was that it would move up by one, not to move upto
the first row, i put in sheet1.section change, but what I think
happens is that you click, it moves up a row, and then it re- does the
sheet1.sectionchange, do you get what I mean?
thanks
 
No problem,

You have to turn off events before the macro moves up one row:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
If ActiveCell.Row > 1 Then
ActiveCell.Offset(-1, 0).Select
End If
Application.EnableEvents = True
End Sub

Best wishes

Per

<[email protected]> skrev i meddelelsen
ActiveCell.Offset(-1,0).select

If the cursor is in row 1 when you try to do this command you will recieve
an error, To avoid this you can do so:

If ActiveCell.Row>1 then
ActiveCell.Offset(-1,0).select
End If

Hopes this helps.

---
Per

"Dean" <[email protected]> skrev i
meddelelsen



- Show quoted text -

Hey thanks for your reply,
but what I meant was that it would move up by one, not to move upto
the first row, i put in sheet1.section change, but what I think
happens is that you click, it moves up a row, and then it re- does the
sheet1.sectionchange, do you get what I mean?
thanks
 
Back
Top