Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 564
- Office Version
- 365
- 2010
- Platform
- Windows
I'm running a test on a userform I made up. I usually split up the main userform that would be used into sections and create another userform to test code because it easier to debug, in my opinion. Once I know the code works without any errors (preferably), I'll add it to the main userform that would be used.
So now I have a userform that contains one combobox(cmbPrdCde), a Submit button and a textbox(TxtBxBulkNum). In this example test, the values that will be used are located in Range("K3:O12"). Range("K1:O1") contain the title of each column I'll list them below for clarification.
Range("K1") = Product Code
Range("L1") = Product Name
Range("M1") = Report Description
Range("N1") = Packaging Size
Range("O1") = Bulk Number
In this test example, I have ten products listed. I only want to populate the combobox with the products that contain the same Bulk Number listed. I included part of the code that I've been using to populate the combobox with ALL the products. If possible I would like to modify the current code.
The code in between the commented "*" is code that I added and the below the bottom commented asterisks is the previous code. I need to somehow connect the two so they work together.
I hope my explanation was detailed enough and thank you.
So now I have a userform that contains one combobox(cmbPrdCde), a Submit button and a textbox(TxtBxBulkNum). In this example test, the values that will be used are located in Range("K3:O12"). Range("K1:O1") contain the title of each column I'll list them below for clarification.
Range("K1") = Product Code
Range("L1") = Product Name
Range("M1") = Report Description
Range("N1") = Packaging Size
Range("O1") = Bulk Number
In this test example, I have ten products listed. I only want to populate the combobox with the products that contain the same Bulk Number listed. I included part of the code that I've been using to populate the combobox with ALL the products. If possible I would like to modify the current code.
The code in between the commented "*" is code that I added and the below the bottom commented asterisks is the previous code. I need to somehow connect the two so they work together.
VBA Code:
If Me.TxtBxBulkNum.Value <> "" Then
'*******************************************************************************************************************
Dim foundBulk As Range
Dim str3 As String
str3 = Me.TxtBxBulkNum.Value
Worksheets("Product_Info").Activate
Set foundBulk = Worksheets("Product_Info").Range("K3", Range("O" & Rows.Count).End(xlUp)).Find(str3)
'*******************************************************************************************************************
With ThisWorkbook.Worksheets("Product_Info")
ary = .Range("K3", .Range("K" & Rows.Count).End(xlUp).Offset(, 1))
ReDim nary(1 To UBound(ary))
For r = 1 To UBound(ary)
nary(r) = ary(r, 1) & " (" & ary(r, 2) & ")"
Debug.Print nary(r)
Next r
Me.cmbPrdCde.List = nary
End With
Else
With ThisWorkbook.Worksheets("Product_Info")
ary = .Range("K3", .Range("K" & Rows.Count).End(xlUp).Offset(, 1))
ReDim nary(1 To UBound(ary))
For r = 1 To UBound(ary)
nary(r) = ary(r, 1) & " (" & ary(r, 2) & ")"
Debug.Print nary(r)
Next r
Me.cmbPrdCde.List = nary
End With
End If
I hope my explanation was detailed enough and thank you.