ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA code to calculate the difference between rows (https://www.excelbanter.com/excel-programming/272790-re-vba-code-calculate-difference-between-rows.html)

Alan Beban[_3_]

VBA code to calculate the difference between rows
 
The range references below will all refer to the active sheet.

Alan Beban

Alan Beban wrote:
E.g., =a2:d2-a1:d1 array entered into a 4-cell row.

If you really want VBA code

Range("a6:d6") = [a2:d2-a1:d1]

Or to put the results into an array instead of dumping them onto the
worksheet

Dim arr()
arr = [a2:d2-a1:d1]

Alan Beban

Desmond wrote:

Hello,
I have two rows of numbers in cells. I need the VBA code that will
subtract each cell value in one line from the cell in the same column
in the other line.

I created a macro that subtracts the first cell and copies across the
row, but with the worksheet protected this does not work. I tried a
recorded macro subtracting each cell separately, and this seems to
work. So I believe I need a loop structure, and I am having trouble
with this.

Your assistance would be appreciated. I know little of programming, so
your help would be valuable

Thanks

desmond






All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com