VBA combo box help

Dr.Evil925

New Member
Joined
Feb 24, 2011
Messages
22
I am trying to get 2 combo box's. The first one should populate with a list of headers and the second with the entries under the header picked in box 1.

Here is what i have so far and box 1 works but box 2 does not.

Private Sub CBName_Drop Button Click()
For Customer = 1 To 50
If Cells(1, Customer).Value = CBCustomer.Value Then
For Each NName In ws.Range("A2:A10")
With Me.CBName
.AddItem NName.Value
End With
Next NName
End If
Next Customer
End Sub

Private Sub UserForm_Initialize()
Dim Cust As Range
Dim ws As Worksheet
Set ws = Worksheets("Account DB")

For Each Cust In ws.Range("A1:M1")
With Me.CBCustomer
.AddItem Cust.Value
End With
Next Cust

The sheet might look like this.

Cust1 Cust2
Jim George

My end result would be for box 1 to show Cust1, and Cust2. with box 2 showing Jim, or George depending on which Cust i pick

Thanks
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Finally figured it out.
Code:
'Clears the combobox "CBName" and fills it with the values in rows 2 - 10
'under the value of combobox "CBCustomer"

Private Sub CBCustomer_Change()
Dim ws As Worksheet
Set ws = Worksheets("Account DB")

Me.CBName.Clear

For Customer = 1 To 50
        If ws.Cells(1, Customer).Value = CBCustomer.Value Then
            For NName = 2 To 10
                With Me.CBName
                .AddItem ws.Cells(NName, Customer).Value
                End With
            Next NName
        End If
Next Customer
End Sub

'Populates a combobox "CBCustomer" with the values in range A1:M1

Private Sub UserForm_Initialize()
Dim Cust As Range
Dim ws As Worksheet
Set ws = Worksheets("Account DB")

For Each Cust In ws.Range("A1:M1")
    With Me.CBCustomer
        .AddItem Cust.Value
    End With
Next Cust

End Sub
 
Upvote 0
With regards to your change event handler, you may want to exit the sub after completion of the second/inner loop, since there's no need to continue checking for the specified customer...

<font face=Courier New>For Customer = 1 To 50<br>        If ws.Cells(1, Customer).Value = CBCustomer.Value Then<br>            For NName = 2 To 10<br>                With Me.CBName<br>                .AddItem ws.Cells(NName, Customer).Value<br>                <SPAN style="color:#00007F">End</SPAN> With<br>            <SPAN style="color:#00007F">Next</SPAN> NName<br>            Exit <SPAN style="color:#00007F">Sub</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> If<br><SPAN style="color:#00007F">Next</SPAN> Customer<br></FONT>

Here's an alternative, which avoids looping and uses a dynamic range for the source data...

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Dim</SPAN> CustomerList <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> wks <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">Dim</SPAN> LastColumn <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CBCustomer_Change()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> MatchVal <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> NamesList <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> NameRange <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> LastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    Me.CBName.Clear<br>    <br>    MatchVal = Application.Match(Me.CBCustomer.Value, CustomerList, 0)<br>    <br>    <SPAN style="color:#00007F">If</SPAN> IsError(MatchVal) <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br>    <SPAN style="color:#00007F">With</SPAN> wks<br>        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row<br>        <SPAN style="color:#00007F">Set</SPAN> NameRange = Range(.Cells(2, 1), .Cells(LastRow, LastColumn))<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    NamesList = Application.Index(NameRange, 0, MatchVal).Cells.Value<br>    <br>    Me.CBName.List = NamesList<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()<br><br>    <SPAN style="color:#00007F">Set</SPAN> wks = Worksheets("Account DB")<br>    <br>    <SPAN style="color:#00007F">With</SPAN> wks<br>        LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column<br>        CustomerList = Range(.Cells(1, 1), .Cells(1, LastColumn)).Cells.Value<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    Me.CBCustomer.List = Application.Transpose(CustomerList)<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Dear Domenic,

First of all, I'm a rookie! :biggrin:
I'm working on the exact same thing as mentioned above.

I'm working in a test area that looks like this:
<table width="320" border="0" cellpadding="0" cellspacing="0"><col style="width: 48pt;" width="64"> <col style="width: 48pt;" width="64"> <col style="width: 48pt;" width="64" span="3"> <tbody><tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt; width: 48pt;" width="64" align="right" height="20">1</td> <td class="xl63" style="width: 48pt;" width="64" align="right">2</td> <td class="xl63" style="width: 48pt;" width="64" align="right">3</td> <td class="xl63" style="width: 48pt;" width="64" align="right">4</td> <td class="xl63" style="width: 48pt;" width="64" align="right">5</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">100</td> <td class="xl63" align="right">200</td> <td class="xl63" align="right">300</td> <td class="xl63" align="right">400</td> <td class="xl63" align="right">500</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">110</td> <td class="xl63" align="right">210</td> <td class="xl63" align="right">310</td> <td class="xl63" align="right">410</td> <td class="xl63" align="right">510</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">120</td> <td class="xl63" align="right">220</td> <td class="xl63" align="right">320</td> <td class="xl63" align="right">420</td> <td class="xl63" align="right">520</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">130</td> <td class="xl63" align="right">230</td> <td class="xl63" align="right">330</td> <td class="xl63" align="right">430</td> <td class="xl63" align="right">530</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">140</td> <td class="xl63" align="right">240</td> <td class="xl63" align="right">340</td> <td class="xl63" align="right">440</td> <td class="xl63" align="right">540</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">150</td> <td class="xl63" align="right">250</td> <td class="xl63" align="right">350</td> <td class="xl63" align="right">450</td> <td class="xl63" align="right">550</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">160</td> <td class="xl63" align="right">260</td> <td class="xl63" align="right">360</td> <td class="xl63" align="right">460</td> <td class="xl63" align="right">560</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">170</td> <td class="xl63" align="right">270</td> <td class="xl63" align="right">370</td> <td class="xl63" align="right">470</td> <td class="xl63" align="right">570</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">180</td> <td class="xl63" align="right">280</td> <td class="xl63" align="right">380</td> <td class="xl63" align="right">480</td> <td class="xl63" align="right">580</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl63" style="height: 15pt;" align="right" height="20">190</td> <td class="xl63" align="right">290</td> <td class="xl63" align="right">390</td> <td class="xl63" align="right">490</td> <td class="xl63" align="right">590</td> </tr> </tbody></table>
Nice and Simple for testing.
I made two combobox elements in one userform.
Both boxes I named to the same names as in your code just to keep the code above as original as possible.
CBCustomer and CBName
I also changed the Sheet naming.

For some reason in my case the Code don't seem to pass the 'MatchVal' check.

The first Combobox Show 1 to 5 as it should.
after clicking any number the MatchVal exits the Sub.
After disabeling the MatchVal the second Combobox shows the first Column (100-190) dispite any number I click in the first combobox.

What is going wrong?

Thanks in advance
 
Upvote 0
Dear Domenic,

First of all, I'm a rookie! :biggrin:
I'm working on the exact same thing as mentioned above.

I'm working in a test area that looks like this:
Nice and Simple for testing.
I made two combobox elements in one userform.
Both boxes I named to the same names as in your code just to keep the code above as original as possible.
CBCustomer and CBName
I also changed the Sheet naming.

For some reason in my case the Code don't seem to pass the 'MatchVal' check.

The first Combobox Show 1 to 5 as it should.
after clicking any number the MatchVal exits the Sub.
After disabeling the MatchVal the second Combobox shows the first Column (100-190) dispite any number I click in the first combobox.

What is going wrong?

Thanks in advance

Try the following instead...

<font face=Calibri><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Dim</SPAN> wks <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">Dim</SPAN> CustomerList <SPAN style="color:#00007F">As</SPAN> Range<br><SPAN style="color:#00007F">Dim</SPAN> LastColumn <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CBCustomer_Change()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> LookupVal <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> MatchVal <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> NamesList <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> NameRange <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> LastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    Me.CBName.Clear<br>    <br>    <SPAN style="color:#00007F">If</SPAN> IsNumeric(Me.CBCustomer.Value) <SPAN style="color:#00007F">Then</SPAN><br>        LookupVal = <SPAN style="color:#00007F">CDbl</SPAN>(Me.CBCustomer.Value)<br>    <SPAN style="color:#00007F">Else</SPAN><br>        LookupVal = Me.CBCustomer.Value<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    MatchVal = Application.Match(LookupVal, CustomerList, 0)<br>    <br>    <SPAN style="color:#00007F">If</SPAN> IsError(MatchVal) <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br>    <SPAN style="color:#00007F">With</SPAN> wks<br>        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row<br>        <SPAN style="color:#00007F">Set</SPAN> NameRange = Range(.Cells(2, 1), .Cells(LastRow, LastColumn))<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    NamesList = Application.Index(NameRange, 0, MatchVal).Cells.Value<br>    <br>    Me.CBName.List = NamesList<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()<br><br>    <SPAN style="color:#00007F">Set</SPAN> wks = Worksheets("Account DB")<br>    <br>    <SPAN style="color:#00007F">With</SPAN> wks<br>        LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column<br>        <SPAN style="color:#00007F">Set</SPAN> CustomerList = Range(.Cells(1, 1), .Cells(1, LastColumn))<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    Me.CBCustomer.List = Application.Transpose(CustomerList)<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Thanks Domenic
This is working great now. Now on to the next problem.
Code:
Private Sub lblCustomer_Click()
Dim ws As Worksheet
Set ws = Worksheets("Account DB")
'verify entry
If cbCust = "" Then
    MsgBox ("Please enter customer account!")
    Else
        'find the customer account name if it exists
        For Customer = 1 To 50
            If ws.Cells(1, Customer).Value = cbCust.Value Then
                'if it exists then send a msgbox
                MsgBox ("Account already exists!")
                Exit Sub
            Else
            'if not then add it to the last available cell
            'find last available cell
            Call Find_Next_Cell_In_Row("Account DB", 1)
            ActiveCell.Value = cbCust.Value
            MsgBox ("Account Added!")
            End If
            Exit Sub
        Next Customer
End If
End Sub
"Find_Next_Cell_In_Row" is
Code:
Public Sub Find_Next_Cell_In_Row(sheet, Row)

Dim ws As Worksheet
Sheets(sheet).Select

Cells(Row, Columns.Count).End(xlToLeft).Offset(0, 1).Select


End Sub
When i click on the label with no account name in the box i get the correct msgbox popup.:biggrin:
when i click on the label with a new account name in the box i get the correct msgbox popup and it adds the name.:biggrin:
when i click on the label with an existing account name in adds the account name then i have a duplicate in the list.:(
I want it to only popup a message stating "Account already exists!"

...What did i miss?

Thanks
 
Upvote 0
Try...

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> lblCustomer_Click()<br>    <SPAN style="color:#00007F">Dim</SPAN> FoundCell <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">If</SPAN> cbCust = "" <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "Please enter customer account!", vbExclamation<br>    <SPAN style="color:#00007F">Else</SPAN><br>        <SPAN style="color:#00007F">With</SPAN> Worksheets("Account DB")<br>            <SPAN style="color:#00007F">With</SPAN> .Rows(1)<br>                <SPAN style="color:#00007F">Set</SPAN> FoundCell = .Find(what:=cbCust.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> FoundCell <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>                .Cells(1, .Columns.Count).End(xlToLeft).Offset(, 1).Value = cbCust.Value<br>            <SPAN style="color:#00007F">Else</SPAN><br>                MsgBox "Account already exists!", vbExclamation<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
brilliant many thanks !

Now the code works I changed the testing to the original sheets.
It all works fine, thanks.

I do have one question though.
In my situation I have 1 Userform with 2 Comboboxes (CBCustomer and CBName), 1 TexxtBox and 3 Commandbuttons (O.K., New Customer and Cancel)
Is there an easy way, after clicking a Commandbutton "O.K.", that a MsgBox pops up and confirmes the results which were entered in the Comboboxes and random text that was entered in the TextBox. (To avoid human error)
Or perhaps even better, instead of a msgbox, another Userform with the results in text. (fully locked) Only with a 'Confirm' and 'Cancel' button.

Cheers
 
Last edited:
Upvote 0
Change the control names (ComboBox1, ComboBox2, TextBox1, and CommandButton1), accordingly...

<font face=Calibri><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Dim</SPAN> CustomerList <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> NameList <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> MatchVal_1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ComboBox1_Change()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> Val_1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <br>    Me.ComboBox2.Clear<br>    <br>    <SPAN style="color:#00007F">With</SPAN> Me.ComboBox1<br>        <SPAN style="color:#00007F">If</SPAN> IsNumeric(.Value) <SPAN style="color:#00007F">Then</SPAN><br>            Val_1 = <SPAN style="color:#00007F">CDbl</SPAN>(.Value)<br>        <SPAN style="color:#00007F">Else</SPAN><br>            Val_1 = .Value<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    MatchVal_1 = Application.Match(Val_1, CustomerList, 0)<br>    <br>    <SPAN style="color:#00007F">If</SPAN> IsError(MatchVal_1) <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br>    Me.ComboBox2.List = Application.Index(NameList, 0, MatchVal_1)<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br><br>    <SPAN style="color:#00007F">If</SPAN> Me.ComboBox1.Value = "" <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "Please enter or select from ComboBox1.", vbExclamation<br>        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    <SPAN style="color:#00007F">If</SPAN> IsError(MatchVal_1) <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "Invalid entry.  Please make a valid entry in ComboBox1.", vbExclamation<br>        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    <SPAN style="color:#00007F">If</SPAN> Me.ComboBox2.Value = "" <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "Please enter or select from ComboBox2.", vbExclamation<br>        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    <SPAN style="color:#00007F">Dim</SPAN> Val_2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> MatchVal_2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br><br>    <SPAN style="color:#00007F">With</SPAN> Me.ComboBox2<br>        <SPAN style="color:#00007F">If</SPAN> IsNumeric(.Value) <SPAN style="color:#00007F">Then</SPAN><br>            Val_2 = <SPAN style="color:#00007F">CDbl</SPAN>(.Value)<br>        <SPAN style="color:#00007F">Else</SPAN><br>            Val_2 = .Value<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    MatchVal_2 = Application.Match(Val_2, Application.Index(NameList, 0, MatchVal_1), 0)<br>    <br>    <SPAN style="color:#00007F">If</SPAN> IsError(MatchVal_2) <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "Invalid entry.  Please make a valid entry in ComboBox2.", vbExclamation<br>        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br>    <SPAN style="color:#00007F">If</SPAN> Me.TextBox1.Value = "" <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "Please enter a value in TextBox1.", vbExclamation<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    <SPAN style="color:#007F00">'etc...</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> wks <SPAN style="color:#00007F">As</SPAN> Worksheet<br>    <SPAN style="color:#00007F">Dim</SPAN> LastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> LastColumn <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    <SPAN style="color:#00007F">Set</SPAN> wks = Worksheets("Account DB")<br>    <br>    <SPAN style="color:#00007F">With</SPAN> wks<br>        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row<br>        LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column<br>        CustomerList = Range(.Cells(1, 1), .Cells(1, LastColumn))<br>        NameList = Range(.Cells(2, 1), .Cells(LastRow, LastColumn))<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    Me.ComboBox1.List = Application.Transpose(CustomerList)<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,259
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top