VBA Case??

Raj7

New Member
Joined
May 25, 2005
Messages
48
Hi, i am using the following code to insert data into corresponding cells chosen by a combo box.

Code:
If cboType.Value = "Cash" And cboQuarter.Value = "Quarter1" Then
    Worksheets("Purchases_Cash_Quarter1").Range("A2").Value = txtDate.Value
    Worksheets("Purchases_Cash_Quarter1").Range("B2").Value = txtSupplier.Value
    Select Case True
        Case cboCategory.Value = "Bank Charges"
            Worksheets("Purchases_Cash_Quarter1").Range("O2").Value = txtAmount.Value
        Case cboCategory.Value = "Camelot Lottery"
            Worksheets("Purchases_Cash_Quarter1").Range("X2").Value = txtAmount.Value
        Case cboCategory.Value = "Contra Entries"
            Worksheets("Purchases_Cash_Quarter1").Range("V2").Value = txtAmount.Value
        Case cboCategory.Value = "Drawings"
            Worksheets("Purchases_Cash_Quarter1").Range("W2").Value = txtAmount.Value
        Case cboCategory.Value = "Electricity"
            Worksheets("Purchases_Cash_Quarter1").Range("M2").Value = txtAmount.Value
        Case cboCategory.Value = "Insurance & Alarm"
            Worksheets("Purchases_Cash_Quarter1").Range("Q2").Value = txtAmount.Value
        Case cboCategory.Value = "Loans & Capital"
            Worksheets("Purchases_Cash_Quarter1").Range("T2").Value = txtAmount.Value
        Case cboCategory.Value = "Miscellaneous & Accounting"
            Worksheets("Purchases_Cash_Quarter1").Range("U2").Value = txtAmount.Value
        Case cboCategory.Value = "Motor Expenses"
            Worksheets("Purchases_Cash_Quarter1").Range("K2").Value = txtAmount.Value
        Case cboCategory.Value = "Postage & Stationery"
            Worksheets("Purchases_Cash_Quarter1").Range("R2").Value = txtAmount.Value
        Case cboCategory.Value = "Rent/Rates/Water"
            Worksheets("Purchases_Cash_Quarter1").Range("L2").Value = txtAmount.Value
        Case cboCategory.Value = "Repairs"
            Worksheets("Purchases_Cash_Quarter1").Range("P2").Value = txtAmount.Value
        Case cboCategory.Value = "Standard Rate"
            Worksheets("Purchases_Cash_Quarter1").Range("E2").Value = txtAmount.Value
        Case cboCategory.Value = "Sundry"
            Worksheets("Purchases_Cash_Quarter1").Range("S2").Value = txtAmount.Value
        Case cboCategory.Value = "Telephone"
            Worksheets("Purchases_Cash_Quarter1").Range("N2").Value = txtAmount.Value
        Case cboCategory.Value = "Wages"
            Worksheets("Purchases_Cash_Quarter1").Range("J2").Value = txtAmount.Value
        Case cboCategory.Value = "Zero Rate: 25%"
            Worksheets("Purchases_Cash_Quarter1").Range("F2").Value = txtAmount.Value
        Case cboCategory.Value = "Zero Rate: 30%"
            Worksheets("Purchases_Cash_Quarter1").Range("G2").Value = txtAmount.Value
        Case cboCategory.Value = "Zero Rate: 5%"
            Worksheets("Purchases_Cash_Quarter1").Range("H2").Value = txtAmount.Value
    End Select
End If

However, when i execute the code it does not seem to insert any code??

any help would be greatly appreciated

Raj
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Raj

I don't think you are using the Select Case correctly.

I don't know exactly what you are trying to do but perhaps the code should look more like this.
Code:
Select Case cboCaterory.Value 
        Case  "Bank Charges" 
            Worksheets("Purchases_Cash_Quarter1").Range("O2").Value = txtAmount.Value 
etc
 
Upvote 0
Thanks...it works brilliantly

Sorry if you hadn't already noticed im a bit of a noobie:)

Thanks again

Raj
 
Upvote 0

Forum statistics

Threads
1,215,410
Messages
6,124,755
Members
449,187
Latest member
hermansoa

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
Back
Top