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
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

sulakvea

Well-known Member
Joined
Jul 2, 2008
Messages
994
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:

sthrncaliguy

Board Regular
Joined
Jul 28, 2009
Messages
213
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,554
Messages
5,596,811
Members
414,104
Latest member
imamalidadashzada

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
Top