Need help on an excel if/then in Macro

Solved/Closed
Gman24 Posts 2 Registration date Thursday March 18, 2010 Status Member Last seen March 19, 2010 - Mar 18, 2010 at 05:11 PM
Gman24 Posts 2 Registration date Thursday March 18, 2010 Status Member Last seen March 19, 2010 - Mar 19, 2010 at 10:36 AM
I'm trying to create an If/Then in Macro for a cell which you input what GPM you want to use. The goal is to stop sales people from making errors and writing in too small of a GPM in the sales write up if working quickly. Say I want the minimum useable GPM to be 6% (not an actual figure, just example), but when a sales associate enters 5% (or less) by accident it automatically changes it to 6%.

If I'm doing it right the if/then statement is: =IF(G612<.06, .06)

But I can't get this to work for me in the way i want it to as mentioned above, or I just don't know how to use Macro. Can anyone help?

TIA

1 response

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Mar 18, 2010 at 10:22 PM
I presume your column of interest is column G

right click the sheet tab and click view code
in the window that comes up copy paste this EVENT CODE

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> Range("G1").Column Then Exit Sub
If Target < 0.06 Then Target = 0.06

End Sub

and save the file

In column G now enter some value <.06 e.g. .03 see what happens to that cell enter more than .06 in some cell in column G. what happens?

give feedback
0
Gman24 Posts 2 Registration date Thursday March 18, 2010 Status Member Last seen March 19, 2010
Mar 19, 2010 at 10:36 AM
That worked, thank you so much!
0