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/272869-re-vba-code-calculate-difference-between-rows.html)

desmond

VBA code to calculate the difference between rows
 
Alan Beban,
Thanks for your help. I used your VBA code and it works.

THere is one major problem. The new range created "a6:d6"
in your reply is "frozen". It will not respond to any
changes made in the selection say A1:d2. This is a severe
limitation for my application, to be effective it has to
respond to changes.
Sorry to bother you again, I should have mentioned this
requirement initially.

Do you see any value in my original suggestion. ie
subtracting the first two cells and looping through the
collection. The worksheet is large and comprises about 60
columns.

My problem is I am not certain if this will work, and I
have trouble programming a loop structure

Thanks for your assistance, I look forward to hearing
from you

desmond
-----Original Message-----
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:15 PM.

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