PDA

View Full Version : Solved: Populating Userform under specific cells



Learner123
11-12-2010, 11:20 AM
I was wodering if someone can help me devlop a code that can:

1. Search for a selected coboBox value (ex: "Churn"), in column A
2. Activates first cell below coboBox value ("Churn")
3. And then inserts a row which populates info from the userform textboxes.

I think I can figure out steps 2 and 3 on my own, but not sure how to go about step 1.

Anyone up for a challenge?

I tried posting this help request on another site, but didn't get anywhere. I have attached a sample excel workbook that I am working with.

Thank you in adavance for your time! :bow:

mdmackillop
11-12-2010, 11:38 AM
Welcome to VBAX.
Something like this

Private Sub Update_Click()
Dim RowCount As Long
Dim c As Range

If Me.ComboBox1.Value = "" Then
MsgBox "Please specify which category you would like to update.", vbExclamation, "NOT SURE WHY"
Me.ComboBox1.SetFocus
Exit Sub
End If

If Me.TextBox1a.Value = "" Then
MsgBox "Please specify vendor.", vbExclamation, "NOT SURE WHY"
Me.TextBox1a.SetFocus
Exit Sub
End If

If Me.TextBox2a.Value = "" Then
MsgBox "Please specify change order dollar amount.", vbExclamation, "NOT SURE WHY"
Me.TextBox2a.SetFocus
Exit Sub
End If

Set c = Columns(1).Find(ComboBox1.Value, lookat:=xlWhole)
If c.Offset(1) = "" Then
Set c = c.Offset(1)
Else
Set c = c.End(xlDown)(2)
End If

c = Me.TextBox1a
c.Offset(, 1) = Me.TextBox2a
c.Offset(, 2) = Me.TextBox3a

End Sub

mdmackillop
11-12-2010, 11:41 AM
BTW. If you do crosspost, (but try not to) please provide links in all locations.
Also please read this (http://www.excelguru.ca/node/7).

Learner123
11-12-2010, 12:10 PM
Thanks for the code MD and for the heads up on forum etiquette. Going forward, I will ensure crossposts are linked.

I have an additional question in regards to the code provided above. Is it possible to alter it so that a whole row is inserted and populated upon clicking "update". I think that this would help keep data from flowing into the other categories.

Also, how do I go about labeling this thread as solved?

Thanks a bunch for your help!!!

mdmackillop
11-12-2010, 12:29 PM
Add the first line here
c(2).EntireRow.Insert
c = Me.TextBox1a

You can mark a thread solved using Thread Tools dropdown (Google Chrome excepted!)

austenr
11-12-2010, 12:33 PM
To label this thread solved, go to Thread Tools at the top of your first post. There is a drop down. Select "Solved".

austenr
11-12-2010, 12:34 PM
Sorry Malcomb beat me to it.

Learner123
11-12-2010, 12:41 PM
Thank you both for your help!