+ Reply to Thread
Results 1 to 17 of 17

Offest (x,y) in a filtered sheet

  1. #1
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Offest (x,y) in a filtered sheet

    Hi

    I need a simple macro that does this:

    ActiveCell.Offset(5, -5).Range("A1").Select

    The problem is that my sheet is filtered and this code counts the invisible rows as well. What do I need to add to the code to consider only visible rows?
    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Offest (x,y) in a filtered sheet

    .SpecialCells(xlCellTypeVisible)
    Last edited by nathansav; 05-28-2014 at 09:40 AM.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    I Googled for an answer but I only found results that are written for going a single row down in a filtered sheet. Your solution is not working unfortunately...
    Last edited by kooocko; 05-28-2014 at 09:42 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Offest (x,y) in a filtered sheet

    Activesheet.SpecialCells(xlCellTypeVisible).Offset(5, -5).Select

    Havent tested. Google's a great way to find these things out.

    About 210,000 results (0.36 seconds) for select visible cells excel vba

  5. #5
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    Googled for an answer but I only found results that are written for going a single row down in a filtered sheet. Your solution is not working unfortunately...

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Offest (x,y) in a filtered sheet

    Quite an interesting problem, not something I've tried to do. Hopefully there's a "built-in" way but one thing I thought of would be like:
    Please Login or Register  to view this content.
    although I have only set that off to do the rows, not the columns as well.

  7. #7
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    OK, I just tried this and it selects the active cell along with 4 visible cells below it. It is a step in the right direction, but all I need is to position the "cursor" (active cell) 5 rows down and 5 columns to the left, counting only the visible cells. The end result should be a single selected cell.

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Offest (x,y) in a filtered sheet

    @nathansav, I don't think that would work. It would try and offset the entire range that you are returning with the .specialcells method to, so would try and select a column -5 from the first visible cell, in the range of visible cells, which would cause an error.

  9. #9
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    @ragulduy, could you please make necessary changes to your code so that it does what I asked?

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Offest (x,y) in a filtered sheet

    hi, I gave you a method for how to do it, you will need to extend it to your particular problem. The idea is to offset one cell at a time and count how many of those cells are hidden/visible, then loop until you have moved enough. So you will need a second loop to do the same as the first but for columns.

  11. #11
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    Columns are not a problem - I can just use the regular ActiveCell.Offset(0, -5) after I have positioned on the 5th row below the original one. The problem is how do I get 5 active rows down and stay on the 5th using the code?

  12. #12
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Offest (x,y) in a filtered sheet

    In the code, rng2 represents the "5 active rows down" cell, so:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    I'm getting this when trying to run:

    error.jpg

  14. #14
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Offest (x,y) in a filtered sheet

    It works fine for me, providing the selected cell is not in columns A-E (as you are offsetting by -5 columns). With, for example, A1 selected, I get the same error as you.

    Try selecting a cell like K5 and trying again.

  15. #15
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    Working \o/

    The only thing I had to edit was "Do Until count = 5" - I set the counter = 6.
    Thanks a lot ragulduy
    One more thing - what is the best way to insert the code into the sheet? I just record a simple macro, set the keyboard shortcut and then edit the code.

  16. #16
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Offest (x,y) in a filtered sheet

    Well nothing wrong with how you do it but wihout recording the macro:
    -Press ALT+F11 to open the vba editor.
    -Click insert->New module and copy the code into the empty module window with an appropraite name for the Sub, for example Sub My_Offset_Macro() instead of Sub Macro_1()
    -Return to the excel workbook window and press ALT+F8, find your macro in the list, select it and press options and then you can assign a shortcut key.

  17. #17
    Registered User
    Join Date
    05-28-2014
    Posts
    9

    Re: Offest (x,y) in a filtered sheet

    Thanks a lot, I owe you one

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Help with offest and countif (Dynamic range)
    By LEEDA12345 in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 02-21-2014, 10:13 AM
  2. [SOLVED] Index,Offest, Match, Wildcard?
    By fgruhlke in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-18-2014, 11:27 PM
  3. [SOLVED] Offest a refernce in 1 sheet as a key to automate information in another sheet
    By jasw529 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-28-2013, 08:20 AM
  4. value in offest cell to match
    By short_n_curly in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2010, 04:02 PM
  5. Page Numbering Offest by Two
    By PJFry in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-16-2005, 12:48 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1