Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cursor movement in Excel macro

    I'm trying to write macro code to move the cursor down one cell in my spreadsheet. I'm familiar with the Activecell. Offset approach, but this moves the cursor down ONE ROW and not necessarily one cell in my spreadsheet. I have hidden rows and columns in my spreadsheet, so I want to move down one 'visible' cell (row) in my spreadsheet. This may mean moving down from row 12 to row 25 since rows 13 - 24 are hidden. While in the spreadsheet, I hit the down arrow and it moves to the next visible row, but how do I accomplish this with a macro while I have hidden rows and columns. I have the same question about moving right or left, but I'm sure the answer will be the 'same.'

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    How about something like:

    Code:
    Do
      ActiveCell.Offset(1, 0).Select
    Loop Until ActiveCell.Rows.Hidden = False
    or for columns:
    Code:
    Do
      ActiveCell.Offset(0, 1).Select
    Loop Until ActiveCell.Columns.Hidden = False

    Steve

  3. The Following User Says Thank You to sdckapr For This Useful Post:

    bwbayquest (2015-02-20)

  4. #3
    New Lounger
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll try that approach when I get a minute. It seems like that will work. I've suspended screen updating during the macro so it won't make the screen jump around as it loops.

  5. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    It shouldn't make the screen jump even if updated, since it will be selecting hidden area so will not be seen anyway...

    Steve

  6. #5
    3 Star Lounger
    Join Date
    Nov 2011
    Location
    Australia
    Posts
    221
    Thanks
    80
    Thanked 3 Times in 2 Posts
    This is just arrow-key code for reference, you simply change the 1's to suit accordingly
    Code:
    Selection.Offset(0, 1).Select      '*Right*
    
    Selection.Offset(0, -1).Select     '*Left*
    
    Selection.Offset(-1, 0).Select     '*Up*
    
    Selection.Offset(1, 0).Select     '*Down*
    
    Selection.Offset(2, 0).Resize(5, 8).Select     '*Down*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •