+ Reply to Thread
Results 1 to 8 of 8

Adding Toggle to Hidden Rows Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2011
    Location
    GA, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Adding Toggle to Hidden Rows Sheet

    Hi guys,

    I am new to the forum and Excel I am designing a spreadsheet for my fantasy football draft. I have written the following code to hide cells as I assign a Team to each player via a drop down box.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng As Range, r As Range
        Set rng = Intersect(Target, Columns(2), Rows("6:" & Rows.Count))
        If Not rng Is Nothing Then
            For Each r In rng
                With r.MergeArea
                    .EntireRow.Hidden = _
                    (.Cells(1).Value = "Team 1") + (.Cells(1).Value = "Team 2") + (.Cells(1).Value = "Team 3") + (.Cells(1).Value = "Team 4") + (.Cells(1).Value = "Team 5") + (.Cells(1).Value = "Team 6") + (.Cells(1).Value = "Team 7") + (.Cells(1).Value = "Team 8") + (.Cells(1).Value = "Team 9") + (.Cells(1).Value = "Team 10")
                End With
            Next
        End If
        Set rng = Nothing
    End Sub
    I know this code can probably be done much simpler but this is the way I could get it to work .

    My problem comes in trying to add a Toggle button to switch my hidden rows on and off. I can't seem to figure out what to do with the duplicate Private Sub that the toggle button code uses.

    I also am having a hard time writing the code to have each player's name show up on the Team's tab after being selected on the Draft Tab. I would like each player to show up in the columns associated with each team by position if possible. For example if Adrian Peterson is drafted by Team 1 he would show up in the RB slot for team 1. If the RB slots are full then that player would show up on the BE.

    I don't know if this is possible but I was hoping someone can help point me in the right direction.

    Thanks,


    TKBulldog
    Attached Files Attached Files
    Last edited by tkbulldog; 08-29-2011 at 10:17 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adding Toggle to Hidden Rows Sheet

    Here's a project I worked on with another OP here in the forum just a couple of weeks ago, seems to be the same idea. Players chosen show up in the specified teams slotted Roster. Overflow players appear on the Bench.

    1) Select a Position in column C
    2) Select a person still available from that position in column D
    3) The lists will shorten themselves as people are drafted, no VBA is used in the project
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-16-2011
    Location
    GA, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Adding Toggle to Hidden Rows Sheet

    JBeaucaire,

    Thank you for your help. I really like the spreadsheet you have created. I am still wondering if it is possible to incorporate a toggle switch with the code I have written? I would like to have a button that would toggle the rows as hidden or not based on the code I have written (based on there being a team name in column 2). Is this possible?

    Thanks,

    Tkbulldog

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adding Toggle to Hidden Rows Sheet

    Everything's possible, of course. But I'm all "footballed out" this season already, so I'll send this to the cavalry.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,355

    Re: Adding Toggle to Hidden Rows Sheet

    Hi TKbulldog,

    See if the attached file with two command buttons doesn't do what you want.
    The code looks like:
    Option Explicit
    
    Sub UnhideAll()
    
        Cells.Select
        Selection.EntireRow.Hidden = False
        Range("B5").Select
    End Sub
    
    Sub HideSelected()
    
    Dim LastPickRow As Double
    Dim RowCtr As Double
    
    LastPickRow = Cells(248, "B").End(xlUp).Row
        For RowCtr = 6 To LastPickRow
            If Len(Cells(RowCtr, "B")) > 0 Then
                Cells(RowCtr, "B").EntireRow.Hidden = True
            End If
        Next RowCtr
        Range("B5").Select
    End Sub
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: Adding Toggle to Hidden Rows Sheet

    Here's another, though I modified sheet 2 for my convenience:
    Attached Files Attached Files
    Ben Van Johnson

  7. #7
    Registered User
    Join Date
    08-16-2011
    Location
    GA, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Adding Toggle to Hidden Rows Sheet

    Hey guys,

    Sorry it has taken me so long to respond. Had to work some crazy hours because of Irene. The spreadsheets work great!
    Thanks for all your help.


    TKBulldog

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adding Toggle to Hidden Rows Sheet

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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