Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
gtslabs
 
Posts: n/a
Default subtraction in a list of numbers that resets with a label.

I have a long list of data in a column with tags or labels at different
intervals in the list. I am trying to subtract each row from the data
point just below the lable. Then when a new label is found the list my
calculations continue but based on the value after the newly found
lable. Can that be done with functions?

For example:

label NA
1 0
3 2
7 6
9 8
label NA
5 0
9 4
15 10
17 12

  #2   Report Post  
Bruno Campanini
 
Posts: n/a
Default subtraction in a list of numbers that resets with a label.

"gtslabs" wrote in message
oups.com...
I have a long list of data in a column with tags or labels at different
intervals in the list. I am trying to subtract each row from the data
point just below the lable. Then when a new label is found the list my
calculations continue but based on the value after the newly found
lable. Can that be done with functions?

For example:

label NA
1 0
3 2
7 6
9 8
label NA
5 0
9 4
15 10
17 12


This is only half an example: give the result you
want to get from operation.

Bruno


  #3   Report Post  
gtslabs
 
Posts: n/a
Default subtraction in a list of numbers that resets with a label.

The result is in the right hand column.
Thanks
Steve

  #4   Report Post  
bpeltzer
 
Posts: n/a
Default subtraction in a list of numbers that resets with a label.

If your input data starts in A1 and you'll allow a 'helper' column B...
In B2: =IF(ISNUMBER(A1),B1,A2) <-- this tracks the value to subtract
In C2: =IF(ISNUMBER(A2),A2-B2,"NA") <-- this becomes your result
--Bruce

"gtslabs" wrote:

The result is in the right hand column.
Thanks
Steve


  #5   Report Post  
Bruno Campanini
 
Posts: n/a
Default subtraction in a list of numbers that resets with a label.

"gtslabs" wrote in message
ups.com...
The result is in the right hand column.
Thanks
Steve


I think it can't be done without a helper column B
as suggested by gtslabs.

Or it can be done with VBA code.
Do you want to have this too?

Bruno




  #6   Report Post  
Bruno Campanini
 
Posts: n/a
Default subtraction in a list of numbers that resets with a label.

"Bruno Campanini" wrote in message
...
Or it can be done with VBA code.
Do you want to have this too?

Bruno


Here it is:

===========================
Sub StrangeCalculations()
Dim SourceRange As Range, TargetRange As Range
Dim StartRange As Range, i, j As Long
Dim PreviousItem

' Definitions
' -----------------------------
Set StartRange = [Sheet2!A281]
Set TargetRange = [Sheet2!B281]
' -----------------------------

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
On Error GoTo ErrHandler

Set SourceRange = Range(StartRange, StartRange.End(xlDown))
ReDim TempArray(1 To SourceRange.Rows.Count)

For Each i In SourceRange
j = j + 1
If Not IsNumeric(i) Then
TargetRange.Offset(j - 1, 0) = "NA"
PreviousItem = i
ElseIf IsNumeric(i) And Not IsNumeric(PreviousItem) Then
TargetRange.Offset(j - 1, 0) = 0
PreviousItem = i
ElseIf IsNumeric(i) And IsNumeric(PreviousItem) Then
TargetRange.Offset(j - 1, 0) = i - PreviousItem
End If
Next

Exit_Sub:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Exit Sub

ErrHandler:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Procedu StrangeCalculations" & vbCrLf & _
ThisWorkbook.FullName
Resume Exit_Sub

End Sub
==================================

Regards
Bruno


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
Seed numbers for random number generation, uniform distribution darebo Excel Discussion (Misc queries) 3 April 21st 23 09:02 PM
Create a new list that singles out duplicate numbers moglione1 Excel Discussion (Misc queries) 1 August 18th 05 06:32 PM
Printing data validation scenarios SJC Excel Worksheet Functions 14 July 24th 05 12:43 AM
list of sequential numbers kellyaek Excel Discussion (Misc queries) 2 December 3rd 04 04:45 PM
how do I add a list of numbers to get a total bibs Excel Discussion (Misc queries) 2 November 27th 04 03:31 AM


All times are GMT +1. The time now is 11:06 PM.

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"