ryancgarrett
Board Regular
- Joined
- Jun 18, 2011
- Messages
- 122
I have the following code to populate some combo boxes on a form, however for some reason it always references the active sheet, rather than the "Data Sheet" like I want it to. Anyone see anything wrong?
Code:
Sub populateComboBox()
Dim lr As Long
With Sheets("Data Sheet")
lr = BlankRow("Data Sheet", 2, 4) - 1
frmTransactionEntry.cbxAccount1.RowSource = .Range("D2:D" & lr).Address(False, False)
frmTransactionEntry.cbxAccount2.RowSource = .Range("D2:D" & lr).Address(False, False)
frmTransactionEntry.cbxAccount3.RowSource = .Range("D2:D" & lr).Address(False, False)
frmTransactionEntry.cbxAccount4.RowSource = .Range("D2:D" & lr).Address(False, False)
frmTransactionEntry.cbxAccount5.RowSource = .Range("D2:D" & lr).Address(False, False)
frmTransactionEntry.cbxAccount6.RowSource = .Range("D2:D" & lr).Address(False, False)
End With
End Sub
'Function to find the end of a list
Function BlankRow(sName As String, sRow As Integer, sCol As Integer) As Integer
Do Until Sheets(sName).Cells(sRow, sCol).Value = Empty
sRow = sRow + 1
Loop
BlankRow = sRow
End Function