Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Excel 2007 - Macro (VB) code for arrow down & arrow up

Using Excel's "Record" macro ignores arrow movements. Could someone please
give me the macro code for down one cell and up one cell.
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 108
Default Excel 2007 - Macro (VB) code for arrow down & arrow up

Hi Grindy,

To go up one cell...

Sub OneUp()
If ActiveCell.Row 1 Then
ActiveCell.Offset(-1, 0).Select
End If
End Sub

Going down use...

ActiveCell.Offset(1, 0).Select

Ed Ferrero
www.edferrero.com
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Excel 2007 - Macro (VB) code for arrow down & arrow up

Thanks for the quick response Ed. A related question...
What is the purpose of the "If/Then" part of your code, ie.

If ActiveCell.Row 1 Then

Just trying to learn why it is needed.

Thanks again,
bob

"Ed Ferrero" wrote:

Hi Grindy,

To go up one cell...

Sub OneUp()
If ActiveCell.Row 1 Then
ActiveCell.Offset(-1, 0).Select
End If
End Sub

Going down use...

ActiveCell.Offset(1, 0).Select

Ed Ferrero
www.edferrero.com

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 108
Default Excel 2007 - Macro (VB) code for arrow down & arrow up

Hi Grindy,

Thanks for the quick response Ed. A related question...
What is the purpose of the "If/Then" part of your code, ie.

If ActiveCell.Row 1 Then

Just trying to learn why it is needed.


If the active cell is in row 1, going up one cell will go to row zero, which
does not exist - you will get an error.

Ed Ferrero
www.edferrero.com

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,934
Default Excel 2007 - Macro (VB) code for arrow down & arrow up

If the ActiveCell is on Row 1, you can't go up (the Offset function would
generate an error if you tried)... the If test makes sure the code doesn't
try. By the way, it might not be clear from Ed's posting, but you don't need
that test for the OneDown macro, but you should test to make sure you aren't
at the bottom of the worksheet...

Sub OneDown()
If ActiveCell.Row < ActiveSheet.Rows.Count Then
ActiveCell.Offset(1, 0).Select
End If
End Sub

--
Rick (MVP - Excel)


"Grindy" wrote in message
...
Thanks for the quick response Ed. A related question...
What is the purpose of the "If/Then" part of your code, ie.

If ActiveCell.Row 1 Then

Just trying to learn why it is needed.

Thanks again,
bob

"Ed Ferrero" wrote:

Hi Grindy,

To go up one cell...

Sub OneUp()
If ActiveCell.Row 1 Then
ActiveCell.Offset(-1, 0).Select
End If
End Sub

Going down use...

ActiveCell.Offset(1, 0).Select

Ed Ferrero
www.edferrero.com




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Excel 2007 - Macro (VB) code for arrow down & arrow up

Wow, you 2 are great!
I completly understand now, and really appreciate both of you taking the
time to explain this stuff to a VB newbee...
I totally get it.... :)
bob

"Rick Rothstein" wrote:

If the ActiveCell is on Row 1, you can't go up (the Offset function would
generate an error if you tried)... the If test makes sure the code doesn't
try. By the way, it might not be clear from Ed's posting, but you don't need
that test for the OneDown macro, but you should test to make sure you aren't
at the bottom of the worksheet...

Sub OneDown()
If ActiveCell.Row < ActiveSheet.Rows.Count Then
ActiveCell.Offset(1, 0).Select
End If
End Sub

--
Rick (MVP - Excel)


"Grindy" wrote in message
...
Thanks for the quick response Ed. A related question...
What is the purpose of the "If/Then" part of your code, ie.

If ActiveCell.Row 1 Then

Just trying to learn why it is needed.

Thanks again,
bob

"Ed Ferrero" wrote:

Hi Grindy,

To go up one cell...

Sub OneUp()
If ActiveCell.Row 1 Then
ActiveCell.Offset(-1, 0).Select
End If
End Sub

Going down use...

ActiveCell.Offset(1, 0).Select

Ed Ferrero
www.edferrero.com



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - Arrow keys backwards in one text box Ted Metro Excel Discussion (Misc queries) 1 July 31st 08 12:02 AM
Excel 2007: Data filter Arrow Chris Setting up and Configuration of Excel 1 April 24th 08 08:50 AM
Using end-arrow down or end-arrow up in a macro Richard Champlin Excel Discussion (Misc queries) 2 September 20th 07 01:12 AM
why dont shift+arrow or ctrl+arrow work in 2007 Naguib Excel Discussion (Misc queries) 1 July 24th 07 04:40 PM
Shift and Arrow Key Code strung New Users to Excel 4 October 28th 05 02:07 PM


All times are GMT +1. The time now is 06:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"