Find the difference between numbers amongst blank cells

pwillia

New Member
Joined
Feb 6, 2012
Messages
34
Hi all,

I have a feeling this problem is not too complicated, but i'm struggling to find a formula to handle it, description below:

Column A contains numbers and #N/A or blank values. If there is a number in cell A1, I would like cell B1 to trigger a formula where it will search down column A to find the next number (skipping blank or #N/A values). Once it has found the next number I would like it to calculate the difference. I would like to implement this down column B. There will be inconsistent gaps between the number values in column A.

Crude example below:

[TABLE="width: 119"]
<tbody>[TR]
[TD]Values:[/TD]
[TD]Difference:[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="align: right"]-10[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]-5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]20[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Please let me know what you think is best here, thank you for your time,

Pete
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Filter out NAs and blanks, apply the formula, you will get what you want.Copy them paste it somewhere else and paste them back after removing the filters.
 
Last edited:
Upvote 0
Hi Bhos123,

Thank you for responding to my question, although I would like to apply a formula which would not require me to filter the data before and after each time the data is refreshed.

Let me know if there are any other ideas out there, would this perhaps require using VBA, I feel this might be a tricky one to handle using formulas alone.

Thanks again,

Pete
 
Upvote 0
Sub Test()
Dim LastCol As Integer
Dim lastrow As Integer
Dim p As Long
Cells(1, 2).Value = "Difference"
Application.ScreenUpdating = False
lastrow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count

For i = 2 To lastrow
If Cells(i, 1) <> "" Then
For j = i + 1 To lastrow
If Cells(j, 1) <> "" Then
Cells(i, 2).Value = Cells(i, 1).Value - Cells(j, 1).Value
Exit For
End If
Next j

End If

Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this formula, copied down. Where I have $20 in the formula, make sure that is a row somewhere below the bottom of your data.

Excel Workbook
AB
1105
2
35-13
4#N/A
5
6
71815
83-2
951
10
11#DIV/0!
12
134
14
Differences
 
Upvote 0
Bhos123 thank you for the code structure, I have gone through it and now better understand the mechanics of VBA for this exercise.

Peter_SSs the formula you have given is spot on for this situation - thank you. I have not seen the index match function used in this way before.

Appreciate you time on this both, this is now solved.

Pete
 
Upvote 0
Glad you have a successful outcome. Thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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