Nested IF VBA using RIGHT function

SimonThom

New Member
Joined
Feb 13, 2017
Messages
12
I need to make two macro buttons that increases and decreases, respectively, the value of a cell based upon it's decimal value.
For example: Cell AA8 currently = 117.292
IF the 3 digits after the decimal point (Right 3) = 317 then add 0.683 to the cell.
IF above is false then check if last digit (Right 1) = 0 or 5, if true then +0.02
IF above is false then add 0.03
The opposite will then need to be applied to the other macro.
For example: Cell AA8 currently = 117.292
IF the 3 digits after the decimal point (Right 3) = 000 then subtract 0.683 from the cell.
IF above is false then check if last digit (Right 1) = 0 or 5, if true then -0.03
IF above is false then subtract 0.02
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
This is what I have been trying, I am new to VBA so there is probably a very obvious solution:

Sub Test_UP()
If Right(aa8, 3) = "317" Then Range("aa8").Value = Range("aa8").Value + 0.683
Else
If Right(aa8, 1) = "0 OR 5" Then Range("aa8").Value = Range("aa8").Value + 0.02
Else
Range("aa8").Value = Range("aa8").Value + 0.03
End If
End If
End Sub
 
Upvote 0
THis has now been resolved :)

Code:
[COLOR=#101094][FONT=Consolas]With[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] Range[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]([/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]"AA8"[/FONT][/COLOR][COLOR=#303336][FONT=Consolas])[/FONT][/COLOR]<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#303336]    [/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Case[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]True[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#101094]Case[/COLOR][COLOR=#303336] Format[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Right[/COLOR][COLOR=#303336](.[/COLOR][COLOR=#303336]Text[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] Len[/COLOR][COLOR=#303336](.[/COLOR][COLOR=#303336]Text[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]-[/COLOR][COLOR=#303336] InStrRev[/COLOR][COLOR=#303336](.[/COLOR][COLOR=#303336]Text[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]DecimalSeparator[/COLOR][COLOR=#303336])),[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]"000"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]"317"[/COLOR][COLOR=#303336]
            [/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]+[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]0.683[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#101094]Case[/COLOR][COLOR=#303336] Right[/COLOR][COLOR=#303336](.[/COLOR][COLOR=#303336]Text[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] Right[/COLOR][COLOR=#303336](.[/COLOR][COLOR=#303336]Text[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]5[/COLOR][COLOR=#303336]
            [/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]+[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]0.02[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#101094]Case[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Else[/COLOR][COLOR=#303336]
            [/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]+[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]0.03[/COLOR][COLOR=#303336]
    [/COLOR][COLOR=#101094]End[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336] [/COLOR]</code>[COLOR=#101094][FONT=Consolas]End[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]With
[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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