Sunil Chandramohan
New Member
- Joined
- Jan 14, 2021
- Messages
- 6
- Office Version
- 2016
- Platform
- Windows
Hi, guys, I have developed a excel user form based data entry for accounting the canteen accounts in my company. The user from has three option buttons. I have a requirement that when the INCOME button is checked the ACCOUNT drop down field should be set as A_Advance, when the DEBIT button is checked the field should be set as B_Loaned and when PURCHASE button is checked it should give drop down list of various account heads as shown. the code works fine until I have to select the PURCHASE button first and then change my selection to INCOME or DEBIT, the drop down list pertaining to PURCHASE still remains, where in it should only narrow to Account heads as I mentioned afore. I realise that the range accRg. gets saved when I check the PURCHASE option. Is there any way to clear that range when I have to select another option button or better still can I remove the drop down property of the combobox if the row count of accRg is only 1 row. I need the the dynamic range defined by the offset worksheet function, incase other account fields get added later on. Some help or thoughts will be definitely appreciated..Thanks in advance
The code for the option buttons I wrote is
The code for the option buttons I wrote is
VBA Code:
Private Sub optDebit_Click()
Dim accRg As Range
Set accRg = Range("OFFSET(Data!$N$1,MATCH(""Debit"",OFFSET(Data!$M$2,0,0,COUNTA(Data!$M:$M)-1,1),0),0,COUNTIF(OFFSET(Data!$M$2,0,0,COUNTA(Data!$M:$M)-1,1),""Debit""),1)")
If accRg.Rows.Count = 1 Then
Me.cboAccount.Value = "B_Loaned"
Else
cboAccount.ListRows = accRg.Rows.Count
Me.cboAccount.List = (accRg)
End If
End Sub
Private Sub optIncome_Click()
Dim accRg As Range
Set accRg = Range("OFFSET(Data!$N$1,MATCH(""Income"",OFFSET(Data!$M$2,0,0,COUNTA(Data!$M:$M)-1,1),0),0,COUNTIF(OFFSET(Data!$M$2,0,0,COUNTA(Data!$M:$M)-1,1),""Income""),1)")
If accRg.Rows.Count = 1 Then
Me.cboAccount.Value = "A_Advance"
Else
cboAccount.ListRows = accRg.Rows.Count
Me.cboAccount.List = (accRg)
End If
End Sub
Private Sub optPurchase_Click()
Dim accRg As Range
Set accRg = Range("OFFSET(Data!$N$1,MATCH(""Purchase"",OFFSET(Data!$M$2,0,0,COUNTA(Data!$M:$M)-1,1),0),0,COUNTIF(OFFSET(Data!$M$2,0,0,COUNTA(Data!$M:$M)-1,1),""Purchase""),1)")
If accRg.Rows.Count = 1 Then
Me.cboAccount.Value = "P_Purchase"
Else
Me.cboAccount.Value = ""
cboAccount.ListRows = accRg.Rows.Count
Me.cboAccount.List = (accRg)
End If
End Sub
Attachments
Last edited by a moderator: