+ Reply to Thread
Results 1 to 16 of 16

VBA to select visible cells with some other cells that are hidden

  1. #1
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Smile VBA to select visible cells with some other cells that are hidden

    Hello, could some one please help me with the following?

    I have been trying to use VBA to select the visible cells of my Excel 2003 worksheet named: 1 Mth. (it contains dummy-data).

    In the attached workbook there are some hidden cells at AA59000:AJ59200

    Please note that the visible data shown in the attached workbook will vary in size each time I run my macro.

    What I need:

    I need please to be able to use VBA to select the visible cells so that I can format the data.

    If any one could please help, it would be greatly appreciated.

    Kind regards,

    Chris
    Attached Files Attached Files
    Last edited by longbow007; 06-09-2010 at 11:41 PM.

  2. #2
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: VBA to select visible cells with some other cells that are hidden

    longbow007;

    First, if the cells are hidden, what difference does it make how they are formatted? That said:

    Please Login or Register  to view this content.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  3. #3
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Smile Re: VBA to select visible cells with some other cells that are hidden

    Hi foxguy, thank you for you valued assistance - much appreciated. I am currently getting a RunTime Error 424 (Object Required) when the macro tries to execute the following code:

    Please Login or Register  to view this content.


    Also, is it possible to change the with statement to include the current active sheet.

    My apologies, sorry I did not make myself very clear in my original post, but I only need to format the visible data, not the hidden data

    Lastly, I added another parenthesis to the following line of code as I was getting an error:

    Please Login or Register  to view this content.
    Cheers,

    Chris
    Last edited by shg; 06-09-2010 at 07:26 PM. Reason: deleted spurious quote

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to select visible cells with some other cells that are hidden

    E.g.,
    Please Login or Register  to view this content.
    Please don't quote whole posts -- it's just clutter.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: VBA to select visible cells with some other cells that are hidden

    Hi shg, sorry I keep replying with whole posts, I simply do not know any other way of replying so that I can post code properly using the Wrap
    Please Login or Register  to view this content.

    However, after running this code, it only selects the visible data in column A.

    My data is visible from column A to column U.

    I am unsure as to why this is happening?

    Could you please help?

    Kind regards,

    Chris
    Last edited by shg; 06-09-2010 at 07:54 PM. Reason: deleted spurious quote

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to select visible cells with some other cells that are hidden

    Just press the Reply button instead of the Quote button.

  7. #7
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: VBA to select visible cells with some other cells that are hidden

    Hi shg, I have just clicked on the Reply button, however I do not have access to the usual set of tools for submitting vba code in the Wrap [Code] tags.

    Maybe I am doing something wrong?

    Cheers,

    Chris.

  8. #8
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: VBA to select visible cells with some other cells that are hidden

    Hi shg, thanks for your code, however when I run it, the entire worksheet has every cell colored in red.

    What I need please is to be able to select all the visible cells (except the hidden ones) so that I can format the visible cells in my macro.

    Kind regards,

    Chris

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to select visible cells with some other cells that are hidden

    My code was a simple example to illustrate that you don't need to select to do almost anything:
    Please Login or Register  to view this content.
    I do not have access to the usual set of tools
    Tools? The button with the pound sign?

    Lacking that, put [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] after.
    Last edited by shg; 06-09-2010 at 09:04 PM.

  10. #10
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: VBA to select visible cells with some other cells that are hidden

    Hi shg, sorry I misunderstood what you were trying to do. Your latest code selects the range A1:AJ65536.

    I do not understand why it will not just select the visible data?

    Kind regards,

    Chris

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to select visible cells with some other cells that are hidden

    Those cells are visible, right?

    For visible cells in the used range, see the change in the prior post.

  12. #12
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: VBA to select visible cells with some other cells that are hidden

    Hi shg, the visible cells in the attached workbook have the range: A1:U51. The hidden cells are in the range: AA59000:AJ59200.

    When I run the following code:

    Please Login or Register  to view this content.
    the selected area is in the range: A1:AJ65536

    Also, when i run the following code:

    Please Login or Register  to view this content.
    the selected area is in the range A1:IV65536

    I only want it to select the range: A1:U51 in this example. This range will vary each time I run my macro.

    I really appreciate your help,

    Kind regards,

    Chris

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to select visible cells with some other cells that are hidden

    Longbow,

    the visible cells in the attached workbook have the range: A1:U51
    If you're referring to the only workbook you posted in this thread, the visible cells are a lot larger than that -- they are all the cells you can see. Line 59200 is the only line I see (at a glance) that's hidden. The used range on the worksheet is A2:AJ59200.

    One way to capture the range A1:U51 is
    Please Login or Register  to view this content.
    You need some way to describe the range of interest that Excel understands.
    Last edited by shg; 06-09-2010 at 11:30 PM. Reason: errant space

  14. #14
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: VBA to select visible cells with some other cells that are hidden

    Hi shg, oops, my mistake - I am a newby and have realized that I have used the wrong terminology to discribe my situation.

    I originally thought that the populated cells in range A1:U51 were the visible ones. But I was incorrect

    I really do not know how to us the code:

    Please Login or Register  to view this content.
    to capture the range A1:U51.


    Each time I run my macro, a different range of data will appear. Suffice to say, the range should not exceed the range A1:U10000

    I simply want to select the data range so that I can format it.

    So, in the above example (in the attached workbook), I would need to select the range A1:U51

    If you could further assist me, it would be greatly appreciated.

    Kind regards,

    Chris

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to select visible cells with some other cells that are hidden

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: VBA to select visible cells with some other cells that are hidden

    Hi shg, that code works very well - thank you very much - much appreciated

    Cheers,

    Chris

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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