richh
Board Regular
- Joined
- Jun 24, 2007
- Messages
- 245
- Office Version
-
- 365
- 2016
Hey all,
Quick question summmary: My loop won't do anything, even though it works like a charm in other program.
I have two surveys I'm conducting. One works great, the other... not so much. I can't get the loop to work in one of them. Is there a reason as to why having too many listboxes on a form to cause a problem?
I have a loop that is supposed to mark an X in a worksheet depending on which boxes the user's check off. There are four listboxes on the form. Each box has a row source with the corresponding column number written in for instance...
FirstList | Corresponding Column
OptionA | 3
OptionB | 4
OptionC | 5
SecList | CorresondingCol
OptionD | 9
OptionE | 10
OptionF | 11
etc...
The list boxes all have column count 2 and the second column is hidden via width. The following is the loop I use in an almost identical form:
Dim ctl As Control
Dim i As Integer
Dim ws As Worksheet
Set ws = Worksheets("Data")
With ws
' Loop through the list box controls to populate the selected items on the visitor list
For Each ctl In Me.Controls
' Check for listbox controls
Select Case TypeName(ctl)
Case "ListBox"
For i = 0 To ctl.ListCount - 1
If ctl.Selected(i) = True Then
' Populate the cell with an x in the appropriate column
intCol = ctl.Column(1, i)
' Populate the cell
.Cells(lRow, intCol).Value = "X"
' Reset the col variable to 0
intCol = 0
End If
Next i
End Select
Next ctl
...
End With
Quick question summmary: My loop won't do anything, even though it works like a charm in other program.
I have two surveys I'm conducting. One works great, the other... not so much. I can't get the loop to work in one of them. Is there a reason as to why having too many listboxes on a form to cause a problem?
I have a loop that is supposed to mark an X in a worksheet depending on which boxes the user's check off. There are four listboxes on the form. Each box has a row source with the corresponding column number written in for instance...
FirstList | Corresponding Column
OptionA | 3
OptionB | 4
OptionC | 5
SecList | CorresondingCol
OptionD | 9
OptionE | 10
OptionF | 11
etc...
The list boxes all have column count 2 and the second column is hidden via width. The following is the loop I use in an almost identical form:
Dim ctl As Control
Dim i As Integer
Dim ws As Worksheet
Set ws = Worksheets("Data")
With ws
' Loop through the list box controls to populate the selected items on the visitor list
For Each ctl In Me.Controls
' Check for listbox controls
Select Case TypeName(ctl)
Case "ListBox"
For i = 0 To ctl.ListCount - 1
If ctl.Selected(i) = True Then
' Populate the cell with an x in the appropriate column
intCol = ctl.Column(1, i)
' Populate the cell
.Cells(lRow, intCol).Value = "X"
' Reset the col variable to 0
intCol = 0
End If
Next i
End Select
Next ctl
...
End With