Where am I going wrong? CBOBox Loop

sthrncaliguy

Board Regular
Joined
Jul 28, 2009
Messages
213
Private Sub CommandButton2_Click()
Dim ws As Worksheet
Dim myList As String
Dim ctlName As String
Dim ctl As Control, cboBox As ComboBox
Set ws = Worksheets("D_Table")
For Each cboBox In UserForm1.Controls
If cboBox.Value <> "" Then
nextrow = ws.Range("A100").End(xlUp).Row + 1
ws.Cells(nextrow, 1).Value = cboBox.Value
End If
Next
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
remove this line and try again..

Dim ctl As Control, cboBox As ComboBox

P.S. ignore that - what is the error you're getting?
 
Last edited:
Upvote 0
remove this line and try again..

Dim ctl As Control, cboBox As ComboBox

P.S. ignore that - what is the error you're getting?


I was able to get it working with the below code:

Code:
Private Sub CommandButton2_Click()
Dim ws As Worksheet
Dim Nextrow As Integer
 
Set ws = Worksheets("DTable")
 
ws.Range("A5:A20").ClearContents
For i = 1 To 10
    If IsEmpty(Me.Controls("ComboBox" & i)) = False Then
        Nextrow = ws.Range("A100").End(xlUp).Row + 1
        ws.Cells(Nextrow, 1).Value = (Me.Controls("ComboBox" & i))
         End If
Next i
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,791
Members
449,188
Latest member
Hoffk036

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