View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JP[_4_] JP[_4_] is offline
external usenet poster
 
Posts: 897
Default Populate Sheet based on ComboBox selection

Is the combo box on a userform? It's much easier that way. I created a
test userform with a single combo box which takes the range in sheet
1, column A and copies matching rows to Sheet 2. It's not much but it
does exactly what you want.

Here is the code behind the userform:

Private Sub CommandButton1_Click()
Dim cell As Excel.Range
Dim rng As Excel.Range

For Each cell In Worksheets("Sheet1").Range("A1",
Range("A65536").End(xlUp))
Set rng = Worksheets("Sheet2").Range("A4")

If CLng(cell.Value) = ComboBox1.Value Then
cell.EntireRow.Copy rng.Offset(1, 0)
End If

Next cell
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim cell As Excel.Range

For Each cell In Worksheets("Sheet1").Range("A1",
Range("A65536").End(xlUp))
ComboBox1.AddItem CLng(cell.Value)
Next cell

End Sub


If you like I can email you a copy.

HTH,
JP



On Mar 4, 8:05*pm, Steve wrote:
No, more like copy the row from Sheet1 and paste it in Sheet2. *Sheet1
will house all the data and be hidden. *The combobox is on Sheet2, so
i would like the appropriate rows ro be pasted beginning on Row5.
Thanks!!

On Mar 4, 5:58*pm, JP wrote:



What do you mean by "bring in" ? Hide?


--JP


On Mar 4, 7:54*pm, Steve wrote:


Hello. *On Sheet2 I have a combo box. *On sheet1 ColA, I have the
"key" for the combobox selections. *So if I choose "Product1" from the
combobox, how do I have vba bring in all the rows that have "Product1"
in Column A? *Bringing in the entire row, or columns 1 thru 8 would be
fine. *Thanks!!- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -