+ Reply to Thread
Results 1 to 6 of 6

Toggle Button multiple row ranges

  1. #1
    Registered User
    Join Date
    11-27-2019
    Location
    Brisbane , Australia
    MS-Off Ver
    2016
    Posts
    27

    Toggle Button multiple row ranges

    Hi all

    Great to be here in this forum.

    Just a question , i have this VBA for toggle hiding/showing a range of rows as below (rows 268 to 279) which works no problem

    Private Sub ToggleButton22_Click()
    Dim xAddress As String
    xAddress = "268:279"

    If ToggleButton22.Value Then
    Application.ActiveSheet.Rows(xAddress).Hidden = True
    ToggleButton22.Caption = "S"
    Else
    Application.ActiveSheet.Rows(xAddress).Hidden = False
    ToggleButton22.Caption = "H"

    End If

    End Sub


    My question would be how would i get this to have multiple ranges for example as above for
    rows 268:279 AND rows 68:79 AND 92:103 all on the same toggle?


    Thanks in advance
    Steve

  2. #2
    Registered User
    Join Date
    11-27-2019
    Location
    Brisbane , Australia
    MS-Off Ver
    2016
    Posts
    27

    Re: Toggle Button multiple row ranges

    please ignore , i worked it out , i should have checked before posting

    Private Sub ToggleButton22_Click()
    Dim xAddress As String
    xAddress = "268:279"
    xxAddress = "68:79"

    If ToggleButton22.Value Then
    Application.ActiveSheet.Rows(xAddress).Hidden = True
    Application.ActiveSheet.Rows(xxAddress).Hidden = True
    ToggleButton22.Caption = "S"
    Else
    Application.ActiveSheet.Rows(xAddress).Hidden = False
    Application.ActiveSheet.Rows(xxAddress).Hidden = False


    ToggleButton22.Caption = "H"

    End If

    End Sub

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Toggle Button multiple row ranges

    Assuming your initial setting for the button's caption is correct for the hidden state for those rows, this should work...
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-27-2019
    Location
    Brisbane , Australia
    MS-Off Ver
    2016
    Posts
    27

    Re: Toggle Button multiple row ranges

    Awesome Rick , tested over 5 ranges works like a charm

    I have 26 ranges to add , should be ok?

    Forgive me for being a novice, i want to make the captions read using your awesome code posted above, can't seem to make it change?
    Hide Term 1 (where my original post was "H")
    Show Term 1 (where my original post was "S")

    Many thanks
    Steve
    Last edited by BrisbaneOz; 11-28-2019 at 07:52 PM. Reason: amended

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Toggle Button multiple row ranges

    Quote Originally Posted by BrisbaneOz View Post
    I have 26 ranges to add , should be ok?
    Maybe... it depends on what the actual rows are. The Range object has a 255 or 256 (can't remember which) limit to the number of characters that can be in its text argument, so if all your rows are less than 1000, it will work fine... if they were all 4-digits long, it would fail... it some but not all are 4-digits long with the rest being 3-digits or less, then it more than likely will work. If your argument is too long, you could alway break the argument into two distinct sets of ranges and use two Range object calls for them.



    Quote Originally Posted by BrisbaneOz View Post
    Forgive me for being a novice, i want to make the captions read using your awesome code posted above, can't seem to make it change?
    Hide Term 1 (where my original post was "H")
    Show Term 1 (where my original post was "S")
    If the problem is that you are displaying H's when you want S's and vice-versa, simply change the "HS" in the Mid function call to "SH" and that should straighten the problem out.

  6. #6
    Registered User
    Join Date
    11-27-2019
    Location
    Brisbane , Australia
    MS-Off Ver
    2016
    Posts
    27

    Re: Toggle Button multiple row ranges

    Thanks Rick , will check on the limits

    Will adopt Caption suggestion , thanks for all your help!
    Last edited by BrisbaneOz; 11-28-2019 at 09:53 PM. Reason: spelling doh!

+ 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. Toggle Button to hide multiple Columns and Rows
    By agillis89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2019, 07:27 AM
  2. [SOLVED] Button to toggle Hide/Show multiple columns
    By lougs7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-01-2018, 04:48 PM
  3. [SOLVED] how do i make a toggle button change other toggle buttons value to false
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-10-2018, 04:19 PM
  4. Replies: 1
    Last Post: 02-13-2014, 10:55 PM
  5. Using VBA toggle button for multiple task
    By dbuff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2013, 03:40 AM
  6. Using VBA toggle button for multiple task
    By dbuff in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-19-2013, 11:27 PM
  7. Hide/Unhide Multiple Sets of Columns with Toggle Button
    By Mischief433 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-06-2012, 05:55 AM

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