+ Reply to Thread
Results 1 to 3 of 3

Selecting rows depending on checkboxes

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Selecting rows depending on checkboxes

    Hi all,

    my question is probably quite simple for the veterans around here: I've got 10 Checkboxes on a userform. The userform contains two textboxes as well. The text in the textboxes is being used to find the values in another sheet and save its row numbers. Then I'd like to select those columns, for which the appropriate checkbox is "checked". So if only the 5 first contain a "tick", i only would like to select those 5. If any other combination is "ticked" (for example 1,3,5,6,7,10) I'd like to select the appropriate columns. I think I'm able to do it but in a very odd way: I'd have to list every possible case - which would be something like 1024 if im not mistaken lol.

    cheers

    threadtitle is wrong: should be columns ofc
    Last edited by Bishonen; 10-13-2012 at 07:21 AM.
    If you think that my answer was helpful, please click on the "Add to this user's Reputation" button.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Selecting rows depending on checkboxes

    Hi, Bishonen,

    if the checkboxes are named CheckBox01, CheckBox02 etc.:
    Private Sub CommandButton1_Click()
    Dim obj As Object
    Dim rngBig As Range
    For Each obj In Controls
      If Left(obj.Name, 8) = "CheckBox" Then
        If obj Then
          If rngBig Is Nothing Then
            Set rngBig = Cells(1, Right(obj.Name, 2) * 1).EntireColumn
          Else
            Set rngBig = Union(rngBig, Cells(1, Right(obj.Name, 2) * 1).EntireColumn)
          End If
        End If
      End If
    Next obj
    If Not rngBig Is Nothing Then
      rngBig.Select  'only check out, no need for Selection otherwise
    End If
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Selecting rows depending on checkboxes

    Vielen Dank Holger,

    in meinem Fall haben die Checkboxes andere Namen als 1,2,3 usw. Dank deines Codes kam ich auf eine Idee wie ich es nun schaffen kann. Vielen Dank
    ---
    Thanks Holger!

+ 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