ryancgarrett
Board Regular
- Joined
- Jun 18, 2011
- Messages
- 122
I have a userform with a listbox and option buttons that populate the listbox from a chart of accounts sheet. Right now my code works and this is what it looks like:
Sub PopulateListBox()
If frmAddAccount.optAsset.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B3:B17"
ElseIf frmAddAccount.optLiability.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B19:B23"
ElseIf frmAddAccount.optOwnerEquity.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B25:B27"
ElseIf frmAddAccount.optRevenue.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B30:B33"
ElseIf frmAddAccount.optExpense.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B35:B53"
End If
End Sub
My problem is that if the user adds more accounts to the program then the range added to the listbox is thrown off. Each account type is assigned a different number, i.e. Assets are between 100 and 199, Liabilities are between 200 and 299 etc. Can I run a loop that determines the range of all asset accounts and then populates the listbox with those accounts if that option is selected, rather than manually defining the range as I have above.
Sub PopulateListBox()
If frmAddAccount.optAsset.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B3:B17"
ElseIf frmAddAccount.optLiability.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B19:B23"
ElseIf frmAddAccount.optOwnerEquity.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B25:B27"
ElseIf frmAddAccount.optRevenue.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B30:B33"
ElseIf frmAddAccount.optExpense.Value = True Then
frmAddAccount.lbxAccountName.RowSource = "'Chart of Accounts'!B35:B53"
End If
End Sub
My problem is that if the user adds more accounts to the program then the range added to the listbox is thrown off. Each account type is assigned a different number, i.e. Assets are between 100 and 199, Liabilities are between 200 and 299 etc. Can I run a loop that determines the range of all asset accounts and then populates the listbox with those accounts if that option is selected, rather than manually defining the range as I have above.