Help, My head hurts

Coopnjaxdad

New Member
Joined
May 12, 2008
Messages
9
This seems like it should be simple, but I can't make it work. I have a spreadsheet taking data through DDE from a NEtDaq and some VB code to move the readings to another sheet and down a row after every scan. That all works fine. I need to calculate the difference between each cell in 2 columns of data, but I don't want to have to do it manually. Can someone please provide some insight?

Thank you.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Couple of ways as an example although there are probably much better ways:

This loops down a column doing the calculation and storing it in a variable:

Code:
Sub Diff()
Dim lastRow As Long, myRange As Range, mySum As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
mySum = 0
For Each myRange In Range("A1:A" & lastRow)
mySum = mySum + myRange.Offset(0, 1).Value - myRange.Value
Next myRange
Range("E1") = mySum
End Sub

and this creates an array formula to do the calculation:

Code:
Sub Diff_Array()
Dim lastRow As Long, myRange As Range, mySum As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
Range("E2").FormulaArray = "=SUM(B1:B" & lastRow & "-A1:A" & lastRow & ")"
End Sub

Both examples take the values in column A from those in B.

Hope it helps,

Dom
 
Upvote 0
I need to calcualte the difference of each pair of cells and have the value end up in sathe C column. So I need to calculate b2-a2=c2, and so on and so forth all the way dow to b3500-a3500=c3500.
 
Upvote 0
My mistake, thought you wanted VB.

This is basically the same array formula as above:<SCRIPT language=JavaScript src="http://www.interq.or.jp/sun/puremis...rl+Shift+Enter. Hope it helps, Dom[/LEFT]
 
Upvote 0
Odds are I am missing something here but, I don't need to sum the differences, I just need the differences. And I need them shown seperately.
 
Upvote 0

Forum statistics

Threads
1,221,596
Messages
6,160,716
Members
451,665
Latest member
PierreF

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