VB code to move cursor 'one cell down?

S

StargateFan

I have a macro in an Excel worksheet that just needs one step added,
to move the cursor one cell down from its current position. Can
someone tell me what the code for that would be?

When I add record the keystroke via moving the down arrow one cell
down, it actually adds the cell reference, which is no good.

Thanks!
 
B

Bob Phillips

Activecell.Offset(1,0).Select

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
S

StargateFan

Activecell.Offset(1,0).Select

Glorious! My macro works perfectly now!

Thank you!

It sure did!

I know have a spreadsheet that has buttons with macros assigned to
them that are found in the workbook itself, all of which has allowed
me to put some great db-like functionality into a spreadsheet! I just
earned my pay! I found out this weekend about how to do all of this.
For years I've been assigning macros to the toolbar but not making
standalone files in this way. Excel is one of the few programs, like
WordPerfect, that has never let me down all these years. No matter
what I've needed, it's come through! Awesome!

:blush:D
 
D

Debra Dalgleish

When you record a macro, turn on Relative Reference to record cell
selection by position, instead of a specific cell address.

For example, select cell D2, and start recording.
Press the Relative Reference button on the Stop Recording toolbar
Press the down arrow key
Turn off Relative Reference, and stop recording

The resulting code is:
ActiveCell.Offset(1, 0).Range("A1").Select

When you run this code, it will move one cell down from whatever is the
active cell.
 
S

StargateFan

When you record a macro, turn on Relative Reference to record cell
selection by position, instead of a specific cell address.

For example, select cell D2, and start recording.
Press the Relative Reference button on the Stop Recording toolbar
Press the down arrow key
Turn off Relative Reference, and stop recording

The resulting code is:
ActiveCell.Offset(1, 0).Range("A1").Select

When you run this code, it will move one cell down from whatever is the
active cell.

Thank you! I appreciate learning this! I'm finally getting a bit
into macro recording. And this will be of great help!

I think what stopped me from getting into this earlier is that in the
16bit days, the recorded macros didn't work in Excel and Word the way
they did in other programs. I never had luck in getting what I needed
(and it was prior 1999, when I first got online at home and then got
into ngs!). Now I find that it does a great job, just like all other
programs do. It's really opened things up for me in last year ever
since I started tentatively exploring VB-based macros (not the easiest
scripting language to get into even with years of experience in others
<lol>!)

:blush:D
 
S

StargateFan

You're welcome! The macro recorder doesn't produce the most efficient
code, but it's a good way to learn about the Excel object model.

Also, David McRitchie has a list of VBA tutorials that may interest you:

http://www.mvps.org/dmcritchie/excel/excel.htm#vbatutorials

Thank you so much for this! As a PSP/Bryce/Poser user, I'm very keen
Thank you! I appreciate learning this! I'm finally getting a bit
into macro recording. And this will be of great help!

I think what stopped me from getting into this earlier is that in the
16bit days, the recorded macros didn't work in Excel and Word the way
they did in other programs. I never had luck in getting what I needed
(and it was prior 1999, when I first got online at home and then got
into ngs!). Now I find that it does a great job, just like all other
programs do. It's really opened things up for me in last year ever
since I started tentatively exploring VB-based macros (not the easiest
scripting language to get into even with years of experience in others
<lol>!)

:blush:D
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top