Consulting

Results 1 to 5 of 5

Thread: Adding to worksheet from ComboBox Selection

  1. #1
    VBAX Regular
    Joined
    Dec 2008
    Posts
    24
    Location

    Adding to worksheet from ComboBox Selection

    Hi all.

    As part of my project I am allowing users to add comments about particular subjects. They click on a command button to add a comment and a userform 'CommentsAC' is shown.

    The combobox is populated with a list from my worksheet with a named range. The user needs to select from this list the asset they want to comment upon. They can then add comments and click "Add Comments".

    I am having issues unfortunately getting the comments added to populate the correct cell on the worksheet, as the cell will differ depending on which item is selected from the list.

    The list items refer to labels on another userform called 'SkillsFom' so I thought that I could write the code to say if the combobox = the caption of a particular label then add text to a particular cell. But it doesn't work.

    I have attached my project in thread "Populating text box in userform with Label Value" and any help would be greatly appreciated.

    Thanks in advance.

    Chris

    Edit Lucas: Link added. Chris, when posting you can copy the url of the page where you want to link to and select the text in your post and hit the globe icon(insert link)

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Chris, Since you are populating your combobox with data from a named range on the matrix sheet you can't very easily use the label captions to qualify your if statement......you have to use the string directly from the column A of sheet matrix. I did the first two of them for you. I also moved your unload me on several of the userforms to get them out of the way:
    [VBA]Private Sub CmdClose_Click()
    With Sheets("Matrix")
    If Me.Asset_List.Value = "VRV UNITS" Then
    .Range("K2").Value = comments.Value
    comments.Value = ""
    End If
    If Me.Asset_List.Value = "AC CHILLER" Then
    .Range("K3").Value = comments.Value
    comments.Value = ""
    End If
    End With
    'Unload Me

    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Regular
    Joined
    Dec 2008
    Posts
    24
    Location
    Steve,

    Wonderful, shame I can't do it from the captions but doing it direct works so I won't complain! My only question now surrounds the unload me statement, why have you moved them? I thought they were necessary or the form would simply stay there when I want it to be removed?

    Sorry to ask simple questions like this but if I am doing things wrong I'd rather look simple than continue to do it!

    Many Thanks

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    No problem with asking questions. That's how we learn.

    On the issue of the unload me statements:

    Use your userform welcome as an example. The code in the "Start Scoring" button which you originally had as:
    [VBA]
    Private Sub Continue_Click()
    Step_One.Show
    Unload Me
    End Sub
    [/VBA]
    run this userform and move it to the right or left before you hit the button. Now hit the button and you will see that your "Start Scoring" userform is still visible.

    If you just move the unload me like this:
    [vba]Private Sub Continue_Click()
    Unload Me
    Step_One.Show
    End Sub[/vba]
    and try the same experiment you will see that the welcome userform is unloaded before the other one is opened......

    The statement is necessary but where you place it makes a huge difference.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Dec 2008
    Posts
    24
    Location
    Steve, got you, makes perfect sense and thanks for explaining. It's amazing how something so simple and obvious can me missed by the ignorant (me)!

    Thanks again, I never thought I could begin to enjoy VBA, but I am!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •