Macro to subtract 1 from current cell

erock_excel

New Member
Joined
Nov 1, 2016
Messages
5
Hello,

I was wondering how to create a macro to subtract 1 from the current cell selected in a spreadsheet? I have a daily summary report that I adjust everyday by subtracting 1 from different cells throughout the summary report. I've tried to record a macro but it puts the location of the current cell (i.e. C5) instead of just current cell.

Is there any way to do this?

Thanks.
 
HI I was wondering, is it possible to update the VBA to deduct not (1), but number from previous cell from the selected range of cells? For example: if I am currently in column "F", can I deduct from numbers in column "F" numbers from column "E" of selected cells?
So, do you mean something like if you are in F3, and the value in F3 is "3" and the value in E3 is "5", you want to run the macro and return "2" (5-3)?
If so, then just run this:
VBA Code:
Sub MyMacro()
    ActiveCell = ActiveCell.Offset(0, -1) - ActiveCell
End Sub
If you meant the opposite (column F minus column E), just flip those two, i.e.
VBA Code:
Sub MyMacro()
    ActiveCell = ActiveCell - ActiveCell.Offset(0, -1)
End Sub
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
HI Joe4, Column "F" ="February" is always a cumulative number of "E" "January" plus transactions happened in "February".
F=10. E=4. So, really, F= 10-4=6.
 
Upvote 0
Joe4. Yours VBA is working,
Sub MyMacro()
ActiveCell = ActiveCell - ActiveCell.Offset(0, -1)
End Sub

But not exactly what I am looking for... In this case I have to go to each cell of 300 and click the macro... Can it be improved that I could select a range of cells to update them?
 
Upvote 0
But not exactly what I am looking for... In this case I have to go to each cell of 300 and click the macro... Can it be improved that I could select a range of cells to update them?
Your question is significantly different than the original question that was asked here.
Since this is a very old thread, you should really start a brand new thread, rather than post your new question onto an old thread. That way, other people will see it as a brand new unanswered question.
 
Upvote 0

Forum statistics

Threads
1,217,050
Messages
6,134,295
Members
449,864
Latest member
daffyduck1970

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