Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get current cell position BEFORE it jumps to next cell

Status
Not open for further replies.

gtaborda

Programmer
May 13, 2007
75
GB
Hi

I use Sub Worksheet_SelectionChange(ByVal Target As Range)
currentcolumn = ActiveCell.Column
currentrow = ActiveCell.Row
...

to detect the current cell position.

However this Sub runs when it jumps to the new Cell.

I need to know the position for the Cell the cursor just left...

For example, I am in CELL A2 and I type "HELLO" then [ENTER] key.
The cursor automatically jumps to cell B2 and the Sub Worksheet_SelectionChange routine gives me cell position for B2 but I want to get the A2 position.

Can anyone help ?
thanks
 
Code:
Private Sub Workbook_Open()
Set Sheet1.rngPrevSel = ThisWorkbook.Windows(1).Selection
End Sub
Code:
Public rngPrevSel As Range, rngOldTarget As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set rngOldTarget = rngPrevSel
Set rngPrevSel = Target
MsgBox rngOldTarget.Address
End Sub



combo
 
gtaborda,

VBA specific questions belong in forum707.

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
The Worksheet_Change event seems to be more convenient for the situation mentioned in the second part of your post.

combo
 
Sorry anotherhiggins, I didn't realize I was on the wrong forum.

Thanks combo for your code...I've tried it but I get some errors...will need to double check it.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top