+ Reply to Thread
Results 1 to 5 of 5

Creating a userform with VBA

Hybrid View

carlton123 Creating a userform with VBA 02-05-2009, 09:57 AM
Andy Pope Re: Creating a userform with... 02-05-2009, 10:13 AM
carlton123 Re: Creating a userform with... 02-05-2009, 01:08 PM
Andy Pope Re: Creating a userform with... 02-06-2009, 06:43 AM
carlton123 Re: Creating a userform with... 02-06-2009, 08:15 AM
  1. #1
    Registered User
    Join Date
    11-16-2007
    Posts
    14

    Creating a userform with VBA

    On a worksheet i have a list of names in Column A the list length can vary this is why i want to create a userform using VBA. The form just wants a checkbox with name next to it for each name in column A. If the checkbox is ticked I want a 'Y' in Column B next to the corresponding name. Hope you can understand and thankyou for any help
    Last edited by carlton123; 02-06-2009 at 09:04 AM.

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

    Re: Creating a userform with VBA

    You can use a Listbox to do that by setting 2 properties.
    No need to create the userform on the fly.

    Userform with Listbox.
    Data in A2:B6

    Private Sub UserForm_Initialize()
    
        Dim rngData As Range
        Dim lngIndex As Long
        
        Set rngData = Range("A2:B6")
        
        With ListBox1
            .ColumnCount = 1
            .MultiSelect = fmMultiSelectMulti
            .ListStyle = fmListStyleOption
            For lngIndex = 1 To rngData.Rows.Count
                .AddItem rngData.Cells(lngIndex, 1).Value
                .Selected(lngIndex - 1) = (rngData.Cells(lngIndex, 2).Value = "Y")
            Next
        End With
    
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-16-2007
    Posts
    14

    Re: Creating a userform with VBA

    thanks I have tried it seems to work apart from it doesnt change the range in the b coloumn any ideas??

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

    Re: Creating a userform with VBA

    You would need to do the reverse of loading the listbox.

    You need to go through the list and if an item is selected write a Y to the correct cell. And clear Y from cell if the item is no longer selected.

  5. #5
    Registered User
    Join Date
    11-16-2007
    Posts
    14

    Re: Creating a userform with VBA

    thank you i had just sorted it out myself and have just read your post. It is the first time i have used a multi select listbox so was unsure how to do this as it is different to a singal select one, anyway thank you all for your help

+ 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