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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,776
Messages
5,833,634
Members
430,221
Latest member
jmmccormick

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