Results 1 to 9 of 9

How to mimic ctrl-select using multiple checkboxes on a form

Threaded View

  1. #1
    Registered User
    Join Date
    07-03-2015
    Location
    brisbane
    MS-Off Ver
    2003
    Posts
    28

    Question How to mimic ctrl-select using multiple checkboxes on a form

    I have a userform that is auto populated with checkboxes that correspond to column headings on an activeworksheet.
    what i want to do is click any combination of checkboes, when I click the command button it selects/copy the column(s) the checkbox relates to so I can then click another command button to open a new worksheet and paste the selection.
    Unfortunately my code will only allow me to select one column at a time and not multiple. please help me, I've spent two days trying to get this to work, i think i have to somehow dd each checkbox to an array or range?

    below is the command button
    Dim LastColumn As Long, CurrColumn As Long
    Dim p As Variant
    Dim MyRange As range, Rng As range, Rng1 As range, Rng2 As range
    Dim chkbox As msforms.CheckBox
    CurrColumn = 1
    LastColumn = ActiveSheet.Cells(CurrColumn, Columns.Count).End(xlToLeft).Column
    For p = LastColumn To CurrColumn Step -1
    Set chkbox = UserForm2.Controls("CheckBox_" & p)
    If chkbox.value = True Then
    Set MyRange = ActiveSheet.range(chkbox.Tag).EntireColumn '.Copy
    End If
    Next p
    MyRange.Copy
    end sub
    
    form code (loads the checkboxes automatically as assigns the tag with the cell reference)
    Private Sub UserForm_Initialize()
    Dim curcolumn   As Long
    Dim LastColumn     As Long
    Dim i           As Long
    Dim chkbox      As msforms.CheckBox
    curcolumn = 1 'Set your column index here
    'LastRow = Worksheets("holding cat").Cells(Rows.Count, curColumn).End(xlUp).Row
    LastColumn = ActiveSheet.Cells(curcolumn, Columns.Count).End(xlToLeft).Column
    For i = 1 To LastColumn
        Set chkbox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & i)
        chkbox.Caption = ActiveSheet.Cells(curcolumn, i).value
        chkbox.Left = 5
        chkbox.Top = 5 + ((i - 1) * 20)
       chkbox.Tag = ActiveSheet.Cells(curcolumn, i).Address
    Next i
    
    End Sub
    Last edited by Leith Ross; 07-05-2015 at 07:05 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Ctrl + Select for multiple selection of cells in VBA
    By Slone in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-22-2022, 04:34 PM
  2. .Select selecting multiple sheets in a form
    By Kris_cs1 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-20-2014, 12:47 AM
  3. Replies: 3
    Last Post: 11-11-2014, 10:27 AM
  4. Disable cut,copy,paste(including ctrl x, ctrl c n ctrl v)
    By Ramboexcel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2014, 01:00 AM
  5. Userform coding to mimic Form Button
    By copernicus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2009, 03:30 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