PDA

View Full Version : Solved: macro to read a cell and subtract a number?



dtms1
07-28-2012, 01:58 PM
Hi,
So I have the excel sheet where one of the columns are all numbers. They are in a format of just XXXXX where X are just digits from 0-9. They are not equations (no = sign in front of cell or formula bar).
However for each column down I would like to subtract a constant number down through all the columns. How can I approach this in VBA to have it do all 5000 cells automatically?

thank you

p45cal
07-28-2012, 02:21 PM
Range("F2").Copy
Range("A2:E130").PasteSpecial Paste:=xlPasteAll, Operation:=xlSubtract
Where F2 contains the number to subtract and A2:E130 are the numbers to subtract from.

dtms1
07-28-2012, 02:29 PM
Wow that did it thanks!

So I'm trying to understand how that code read the existing numbers and did not overwrite the existing numbers being subtracted?

EDIT: Nvm i see it now, its a function within excel itself if you go to the paste option menu you can add operations to the pasting.
Got it, Thank you so much! never knew excel had that option when pasting.