excel macro - move from cell to cell

dgreene18

New Member
Joined
Jan 20, 2005
Messages
6
what is the script that tells the curser in an excel spreadsheet to move from cell b1 to cell d20?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
thanks for the help...but i do not think i articulated the question.

background....in the past i have used the "old" excel macro language. i had loops which counted the number of "passes" then let me use the "counted loops" and goto a cell that was the number of counts from the original cursor position.

example

if the original cursor position was in cell a1 and the number of "passes" were 12...then i would "move the cursor" to cell a13.

using the vba script...how can i command the macro to effectively move the cusrsor to 12 positions (up or down or left or right) based on the loop.
 
Upvote 0
I don't think I'm very clear on what you want and also I do not know the old macro language. But if you want to move the selection from one cell to another cell based on the loop you can say
Code:
Select.Range("A" & i)
where i is your loop variable
 
Upvote 0
let me restate an even more simple question (which will answer my question)...

if the cursor (in the spreadsheet) is in a1...and i want the cursor to move 6 cells to the right....what would be the appropriate script using vba?
 
Upvote 0
i understand your reply was in vba...but i do not understand how to write a script (using the example of cursor on a1 i want the cursor to move to the right by 6 cells (to a7)....

sorry if i am being thick
 
Upvote 0
Ohh..
ok. Now I understand. here you go.
This is the code you should use:
Code:
Sub movecell()
i = 10
ActiveCell.Offset(rowOffset:=0, columnOffset:="" & i).Activate
End Sub

Here are the instructions where to type the code:
1. Open the VBE with Alt-F11.
2. Open the Project Explorer with control-R (it might already be open, that's OK.)
3. Select the file you're working on in that window by clicking it.
4. Select Insert, Module from the drop down menus.
5. Open the Code window by pressing F7. This, too, might be open already.
6. Copy Paste/Write the code.
8. Run the code by pressing F5 from the VBE or from Excel under the Tools, Macro, Macros menu.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,212,933
Messages
6,110,752
Members
448,295
Latest member
Uzair Tahir Khan

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