VBA to record the position of the cursor

bbran19

New Member
Joined
Jan 30, 2012
Messages
49
Office Version
  1. 365
Platform
  1. Windows
I plan to develop a macor to modify the formula in the cell to the left of the cursor.

I am after a code that will select and copy the formula of the cell to the left of the cursor.

I am using

Range("A1").Offset(0,-1).Select

but I was hoping the replace A1 with the current cursor position.

Any help appreciated.

Thanks Bob
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
VBA Code:
Public Sub ChangeSelectedCell()
  Dim addr
  Dim cellvalue
  Dim formula
  
  'Save current selected cell address, value and formula
  With Selection
    addr = .Address 'store the current cursor position
    cellvalue = .Value 'get the value of current active/selected cell
    formula = .formula 'get the formula for the selected cell
    If .Column > 1 Then .Offset(0, -1).Select 'move the cursor left one cell
  End With
End Sub

I think your problem is that you have a range address in your Range("A1") ... statement.

Use "Selection." for the current active/selected cell.

Of course if you are column A you cannot move the cursor left.

I hope this helps.
 
Upvote 0
Solution
VBA Code:
Public Sub ChangeSelectedCell()
  Dim addr
  Dim cellvalue
  Dim formula
 
  'Save current selected cell address, value and formula
  With Selection
    addr = .Address 'store the current cursor position
    cellvalue = .Value 'get the value of current active/selected cell
    formula = .formula 'get the formula for the selected cell
    If .Column > 1 Then .Offset(0, -1).Select 'move the cursor left one cell
  End With
End Sub

I think your problem is that you have a range address in your Range("A1") ... statement.

Use "Selection." for the current active/selected cell.

Of course if you are column A you cannot move the cursor left.

I hope this helps.
Thank you. I will try that now.
 
Upvote 0
You asked for the cursor position, I think you meant to say 'Selected cell'. The cursor means where the mouse is currently pointing at.
 
Upvote 0
You asked for the cursor position, I think you meant to say 'Selected cell'. The cursor means where the mouse is currently pointing at.
Of course you are perfectly correct, johnny. Please forgive my incompetence.
 
Upvote 0

Forum statistics

Threads
1,215,204
Messages
6,123,630
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top