Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default VBA code to calculate the difference between rows

Desmond,

The following code subtracts the cells in row 2 from the cells in row 1 and places the results in an array:

Sub Difference()
Dim i As Integer
Dim dResult(1 To 10) As Double

For i = 1 To 10
dResult(i) = Cells(1, i).Value - Cells(2, i).Value
Next i
End Sub


--

John Green - Excel MVP
Sydney
Australia


"Desmond" wrote in message ...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro code to hide rows and not calculate hidden rows bradmcq Excel Discussion (Misc queries) 0 September 1st 09 12:38 AM
how to calculate time difference in hh:mm:ss bobby t Excel Discussion (Misc queries) 6 July 19th 07 02:48 PM
Calculate the difference between two times Buffgirl71 Excel Worksheet Functions 3 February 10th 06 12:05 AM
Calculate the difference between two times Buffgirl71 Excel Worksheet Functions 1 February 9th 06 10:10 PM
Calculate the difference between two times Svetlana Excel Worksheet Functions 3 July 13th 05 10:02 PM


All times are GMT +1. The time now is 07:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"