How to Summarize between step?
I assummed the input was a sttring. Here is the code
Sub getsteps()
Dim inputstring As String
Dim step As String
Dim Maxstep As Integer
Maxstep = 7
inputstring = "1-2, 2-3, 3-5, 6-10"
inputstring = Trim(inputstring)
step = 0
Do While InStr(inputstring, ",") 0
step = Left(inputstring, InStr(inputstring, ",") - 1)
inputstring = Mid(inputstring, InStr(inputstring, ",") + 1)
pulse = pulse + getpulse(step, Maxstep)
Loop
pulse = pulse + getpulse(inputstring, Maxstep)
End Sub
Function getpulse(step As String, Maxstep As Integer)
getpulse = 0
minusposition = InStr(step, "-")
getlowernumber = Val(Left(step, minusposition - 1))
getuppernumber = Val(Val(Mid(step, minusposition + 1)))
If getlowernumber < Maxstep Then
If getuppernumber Maxstep Then
getuppernumber = Maxstep
End If
getpulse = getuppernumber - getlowernumber
End If
End Function
"Tamil" wrote:
I have data sets like 1-2, 2-3, 3-5, 6-10. I want to extract 1-7 step
interval, this should be (1-2)=1+(2-3)=1+(3-5)=2+(6-7)=1 will be a
total of 5. This way, I have bulk data and want to extract many step
intervals. Any short cut method of macro or good formula will be very
useful to me. Thanks in advance.
- Panneer
|