Quick Macro Question for Sales Spreadsheet

SkzDaLimit

Board Regular
Joined
Dec 1, 2002
Messages
54
Another quick mystery to solve. I tried modifying a macro from a previous spreadsheet you all helped me on to try and make this work.

G23 contains the total amount of money received for an item.
I23 is a drop down with 3 different payment options: PayPal, Amazon Payment and Google Checkout.

PayPal and Google use the same formula to compute the final fee in J23: =IF($G23>0,$G23*2.9%+0.3)

Amazon uses a 2 tier system thus the formula: =IF($G23>10,$G23*2.9%+0.3,IF($G23<=10,$G23*5%+0.05))

This is the macro I came up with:

Private Sub Worksheet_Change(ByVal Target As Range)
' Michael Alan Johnson, 10/04/2011
If Intersect(Target, Range("I23:I1000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Range("J" & Target.Row) = 0
With Application
.EnableEvents = False
.ScreenUpdating = False
Select Case Target.Value
Case "PayPal"
'=IF($G23>0,$G23*2.9%+0.3)
'=IF(G23>0,G23*2.9%+0.3)
Range("J" & Target.Row).FormulaR1C1 = "=IF($G23>0,$G23*2.9%+0.3)"
Case "Amazon Payment"
'=IF($G23>10,$G23*2.9%+0.3,IF($G23<=10,$G23*5%+0.05))
'=IF(G23>10,G23*2.9%+0.3,IF(G23<=10,G23*5%+0.05))
Range("J" & Target.Row).FormulaR1C1 = "=IF($G23>10,$G23*2.9%+0.3,IF($G23<=10,$G23*5%+0.05))"
Case "Google Checkout"
'=IF($G23>0,$G23*2.9%+0.3)
'=IF(G23>0,G23*2.9%+0.3)
Range("J" & Target.Row).FormulaR1C1 = "=IF($G23>0,$G23*2.9%+0.3)"
End Select
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub

Can't seem to get it to work....... :confused:
Excel Workbook
GIJ
21Total ReceivedCheckout MethodCheckout Fee
22
23$12.00
...
Excel 2003

 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Okay, again, I will state, you can use code like this to avoid having to put a formula in the cells:
Code:
Range("J" & Target.Row).Value = Range("G" & Target.Row).Value * 2.9% + 0.3

If you want to add a formula, the formula I provided would work fine:
Code:
=ROUND(IF(AND(I22="Amazon Payment",G22<=10),G23*5%+0.05,G23*2.9%+0.3),2)

The point is that you have said that neither of these solutions work for you. So where are you stuck? What is wrong with my formulas? What is wrong with:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("I23:I1000")) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    If Target = "" Then Range("J" & Target.Row) = 0
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        Range("J" & Target.Row).FormulaR1C1 = "=ROUND(IF(AND(I" & Target.Row & "=""Amazon Payment"",G" & Target.Row & "<=10),G" & Target.Row & "*5%+0.05,G" & Target.Row &"*2.9%+0.3),2)
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub
 
Upvote 0
My apologies, nothing wrong with your suggestions at all. As I have stated, I have a difficult time grasping some of the more complicated things about Excel. I guess I am one of those folks you have to hold my hand and talk me through everything.

Anyways, I tried the last suggestion:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)     
If Intersect(Target, Range("I23:I1000")) Is Nothing Then Exit Sub     
If Target.Count > 1 Then Exit Sub     
If Target = "" Then Range("J" & Target.Row) = 0     
With Application         
.EnableEvents = False         
.ScreenUpdating = False         
Range("J" & Target.Row).FormulaR1C1 = "=ROUND(IF(AND(I" & Target.Row & "=""Amazon Payment"",G" & Target.Row & "<=10),G" & Target.Row & "*5%+0.05,G" & Target.Row &"*2.9%+0.3),2)       .EnableEvents = True         
.ScreenUpdating = True     
End With End Sub
Got a #NAME? error. Thanks again.
 
Last edited:
Upvote 0
What does the formula in the cell say? Is it correct? If not, where's the error?

I understand that you want to be led through step by step, but you need to put some effort into finding where the problem is yourself...
 
Upvote 0
What does the formula in the cell say? Is it correct? If not, where's the error?

I understand that you want to be led through step by step, but you need to put some effort into finding where the problem is yourself...

Sorry, should have put the formula in there:

=ROUND(IF(AND('I23'="Amazon Payment",'G23'<=10),'G23'*5%+0.05,'G23'*2.9%+0.3),2)

The #NAME? error appears in J23 where the fee should have gone.
 
Last edited:
Upvote 0
You don't need to put the formula in anywhere.
Simply copy the code correctly and paste it into the Sheet module.
I note that your last response has the code pasted incorrectly.
Try this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("I23:I1000")) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    If Target = "" Then Range("J" & Target.Row) = 0
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        .Range("J" & Target.Row).Formula = "=ROUND(IF(AND(I" & Target.Row & "=""Amazon Payment"",G" & Target.Row & "<=10),G" & Target.Row & "*5%+0.05,G" & Target.Row & "*2.9%+0.3),2)"
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub
 
Upvote 0
You don't need to put the formula in anywhere.
Simply copy the code correctly and paste it into the Sheet module.
I note that your last response has the code pasted incorrectly.
Try this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("I23:I1000")) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    If Target = "" Then Range("J" & Target.Row) = 0
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        .Range("J" & Target.Row).Formula = "=ROUND(IF(AND(I" & Target.Row & "=""Amazon Payment"",G" & Target.Row & "<=10),G" & Target.Row & "*5%+0.05,G" & Target.Row & "*2.9%+0.3),2)"
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub

Worked liked a charm and many many thanks!
 
Upvote 0
Glad you managed to get it sorted thanks for the feedback....Sal did all the hard yards !!
I think the final problem was here
Rich (BB code):
Range("J" & Target.Row).FormulaR1C1   'this shouldn't be R1C1
 
Upvote 0
Glad you managed to get it sorted thanks for the feedback....Sal did all the hard yards !!
I think the final problem was here
Rich (BB code):
Range("J" & Target.Row).FormulaR1C1   'this shouldn't be R1C1

Many thanks to Sal as well. I did learn a few things so all is good.... :)
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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