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.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Activecell = Activecell - 1

How would you debug the following:
Sub Minus_one()
'
' Minus_one Macro
' Report summary to subtract one from current cell
'

'
ActiveCell.Offset(-2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = ActiveCell - 1
ActiveCell.Offset(0, 1).Range("A1").Select
End Sub

I get a runtime error 13 type mismatch.

Thank you!
 
Upvote 0
Why are you trying to do all that?
If you just want to subtract one from the current cell, you should just be able to use the line of code supplied by ExcelGuyDude:
Code:
Sub Minus_one()
'
' Minus_one Macro
' Report summary to subtract one from current cell
'
    Activecell = Activecell - 1

End Sub
 
Last edited:
Upvote 0
The first question I would have is why are you needing to select other cells?

To answer your question, you are referencing a cell incorrectly. ActiveCell is already referencing a "range"... hence you don't need to say Range("A1")

You can skip the steps of selecting a cell, and rather just change the value of the cell two rows above.

Either way, here is how you would fix your code:
Code:
ActiveCell.Offset(-2, 0).Select
ActiveCell = ActiveCell - 1
ActiveCell.Offset(0, 1).Select
 
Upvote 0
Why are you trying to do all that?
If you just want to subtract one from the current cell, you should just be able to use the line of code supplied by ExcelGuyDude:
Code:
Sub Minus_one()
'
' Minus_one Macro
' Report summary to subtract one from current cell
'
   Activecell = Activecell - 1

End Sub

The other code came over from the 'record macro' button. I'm fresh to using macros and didn't know it wasn't needed. The above formula does the trick. Thanks for your help. I'm really starting to enjoy the power of macros in Excel!!
 
Upvote 0
Why are you trying to do all that?
If you just want to subtract one from the current cell, you should just be able to use the line of code supplied by ExcelGuyDude:
Code:
[COLOR=#333333]Sub Minus_one()[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]' Minus_one Macro[/COLOR]
[COLOR=#333333]' Report summary to subtract one from current cell[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]    Activecell = Activecell - 1
[/COLOR]
[COLOR=#333333]End Sub[/COLOR]

Is there a way to display the formula in formula bar once the macro has been executed? So if the cell value is 111 and after the macro runs the formula bar shows "=111-1".
 
Upvote 0
The code would be

Rich (BB code):
Sub Minus_one()
'
' Minus_one Macro
' Report summary to subtract one from current cell
'
    Activecell = "=" & Activecell  & "- 1"

End Sub
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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