+ Reply to Thread
Results 1 to 3 of 3

Loops for non-continuous range or using named ranges

  1. #1
    Registered User
    Join Date
    08-23-2020
    Location
    Dubai, UAE
    MS-Off Ver
    365
    Posts
    10

    Lightbulb Loops for non-continuous range or using named ranges

    Hello,

    I have written a code on VBA to have a button which shows/hides cells based on specific column addresses. Unfortunately, I think this is not the ideal way, since if someone adds a row, the entire code will have to be re-written. Is there any way to have this done either through loops, or by using named ranges? I would really appreciate if someone could show me how to do it. This is a sample of my code:

    Sub ShowHideSemesterBudgets()

    Dim S1Budget As String
    Dim S2Budget As String
    S1Budget = "F"
    S2Budget = "AZ"

    If Columns(S1Budget).EntireColumn.Hidden = False Then
    Columns(S1Budget).EntireColumn.Hidden = True
    Else
    Columns(S1Budget).EntireColumn.Hidden = False
    End If

    If Columns(S2Budget).EntireColumn.Hidden = False Then
    Columns(S2Budget).EntireColumn.Hidden = True
    Else
    Columns(S2Budget).EntireColumn.Hidden = False
    End If
    End Sub


    Thanks a bunch!

    Best,

    Will

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: Loops for non-continuous range or using named ranges

    Please add code tags to your post




    Perhaps something like this

    Please Login or Register  to view this content.
    Or using named range
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-23-2020
    Location
    Dubai, UAE
    MS-Off Ver
    365
    Posts
    10

    Re: Loops for non-continuous range or using named ranges

    Thanks Andy!!! It worked!!

+ 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. Replies: 11
    Last Post: 07-14-2020, 09:31 AM
  2. Replies: 4
    Last Post: 06-25-2019, 04:57 PM
  3. Looping Mutliple Named Resized Ranges in next empty row below another named range
    By gingumdog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2014, 08:15 PM
  4. [SOLVED] Determining if the value of a cell can be a named range, then assigning named ranges after
    By Romulo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2013, 06:05 PM
  5. Loop through non-continuous named range in vba
    By awan0126 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-26-2011, 02:56 PM
  6. Replies: 1
    Last Post: 03-21-2006, 06:40 PM
  7. [SOLVED] For Loops and Named ranges
    By Ronnie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2005, 09:25 PM

Tags for this Thread

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