PDA

View Full Version : Adding to worksheet from ComboBox Selection



mayerc
01-02-2009, 05:05 AM
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" (http://www.vbaexpress.com/forum/showthread.php?t=24447) 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)

lucas
01-02-2009, 10:40 AM
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:
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

mayerc
01-05-2009, 02:55 AM
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

lucas
01-05-2009, 09:59 AM
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:

Private Sub Continue_Click()
Step_One.Show
Unload Me
End Sub

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:
Private Sub Continue_Click()
Unload Me
Step_One.Show
End Sub
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.

mayerc
01-06-2009, 05:17 AM
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!