This is a discussion on excel macro - move from cell to cell within the Excel Questions forums, part of the Question Forums category; what is the script that tells the curser in an excel spreadsheet to move from cell b1 to cell d20?...
what is the script that tells the curser in an excel spreadsheet to move from cell b1 to cell d20?
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.
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.
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
where i is your loop variableCode:Select.Range("A" & i)
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?
But what I said is VBA.
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
ok. Now I understand. here you go.
This is the code you should use:
Here are the instructions where to type the code:Code:Sub movecell() i = 10 ActiveCell.Offset(rowOffset:=0, columnOffset:="" & i).Activate End Sub
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.