+ Reply to Thread
Results 1 to 10 of 10

Simplify VBA code for hiding Column and range based on a cell value

  1. #1
    Registered User
    Join Date
    09-21-2018
    Location
    Hong Kong
    MS-Off Ver
    Office 365 version 16
    Posts
    17

    Simplify VBA code for hiding Column and range based on a cell value

    I have written a VBA code that does 2 things. 1) It hides Column based on a cell value. 2) hides a range of row based on a cell value of another sheet. The issue is I have quite a lot of range of row that needs to be hidden so my code become quite lenghtly for doing 2). The code is working fine but I was wondering if there were a better more efficient way of doing this.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,081

    Re: Simplify VBA code for hiding Column and range based on a cell value

    You can reduce the amount of code like
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Simplify VBA code for hiding Column and range based on a cell value

    Hi DFHK,

    You could build the part that repeats all the time into a Sub with arguments you can shorten the whole thing to single line for each column


    Grtz

  4. #4
    Registered User
    Join Date
    09-21-2018
    Location
    Hong Kong
    MS-Off Ver
    Office 365 version 16
    Posts
    17

    Re: Simplify VBA code for hiding Column and range based on a cell value

    Thanks for the hints. However there is a bug preventing to run the macro proerperly. Range "Section1" is in "proposal" worksheet whereas Range "S1Controller" is in resources worksheet. Could it be the problem?

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,081

    Re: Simplify VBA code for hiding Column and range based on a cell value

    You just need to remove the . from the Section ranges like
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Simplify VBA code for hiding Column and range based on a cell value

    I like this bit of code from Fluff

    Please Login or Register  to view this content.
    I have never seen that before.

    However if you used a helper column you could achieve that without a loop. So much faster.


    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  7. #7
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,285

    Re: Simplify VBA code for hiding Column and range based on a cell value

    How about like this
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-21-2018
    Location
    Hong Kong
    MS-Off Ver
    Office 365 version 16
    Posts
    17

    Re: Simplify VBA code for hiding Column and range based on a cell value

    Hi FLuff13, Thanks for this, much appreciated! It works like a charm and it is much easier to read! Thanks so much!

  9. #9
    Registered User
    Join Date
    09-21-2018
    Location
    Hong Kong
    MS-Off Ver
    Office 365 version 16
    Posts
    17

    Re: Simplify VBA code for hiding Column and range based on a cell value

    Thanks mehmetick, this is much appreciated! I am still trying to get my head around this, but I can see the value of your approach. Thanks!

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,081

    Re: Simplify VBA code for hiding Column and range based on a cell value

    Glad we could help & thanks for the feedback

+ 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. Please simplify code to change the range for a name.
    By david killoran in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-03-2017, 12:20 PM
  2. [SOLVED] VBA - Condense code for hiding/unhiding cell based on value in cell above
    By arundh in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-02-2013, 03:19 PM
  3. I need the code for hiding a column if a cell in that column has no date.
    By Martynoxon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2013, 11:17 AM
  4. [SOLVED] need help re hiding rows in a range based on cell contents
    By jimredfield in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-30-2012, 06:53 PM
  5. Hiding a column based on 2 or more cell values
    By excelfan2010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2010, 09:43 AM
  6. VBA code for hiding columns based on cell value
    By Aramis06 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2010, 01:21 PM
  7. Hiding Rows in a Range based on column A value
    By tig in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-09-2006, 01:10 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