Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to Summarize between step?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to Summarize between step?

Thanks Joel.
The data is contained in excel as numbers in A1:B4 (A1=1, B1=2, A2=2,
B2=3, etc).
The step 1-7, I put in A5:B5 (A5=1, B5=7).

I dont have knowledge on macro coding. Can you please modify the code?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to Summarize between step?

Use function below. call with

=GetStep(A1:B5)
Will work with any range of cells 5 rows x 2 columns

If you have variable size ranges I would recommend doing the following and
then I would modify the code again.

A B C D E
Row 1 1 1 2 3 6

Row 2 7 2 3 5 10


Where column A is the min and max limits, and data is in columns rather than
rows. You can continue adding more steps in columns f and up.



This code works with the way you asked for the code to be written.

Function GetStep(Target As Range)

Dim MinStep As Integer
Dim MaxStep As Integer

MinStep = Target(5, 1)
MaxStep = Target(5, 2)

GetStep = 0
For RowCount = 1 To 4

LowerNumber = Target(RowCount, 1)
UpperNumber = Target(RowCount, 2)


If LowerNumber < MinStep Then

LowerNumber = MinStep

End If

If UpperNumber MaxStep Then

UpperNumber = MaxStep

End If

GetStep = GetStep + (UpperNumber - LowerNumber)

Next RowCount

End Function

"Joel" wrote:

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to Summarize between step?

Thanks Joel,

It works great.
Now I need to expand the function to cover more work.
I have many numbers from to in A1: B300

I have many steps from to in A302: B310

I have to call the function Getstep manytimes or any shortcut?

Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to Summarize between step?

You don't have to change the function unless you have to add more steps. As
I recommended put the limits of the step as the first entry, then it is easy
for me to change the range of the function to work with variable numbers of
steps.

The fnction works like any other functon that you can copy it to other cells.

"Tamil" wrote:

Thanks Joel,

It works great.
Now I need to expand the function to cover more work.
I have many numbers from to in A1: B300

I have many steps from to in A302: B310

I have to call the function Getstep manytimes or any shortcut?

Thanks


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to Summarize between step?

Thanks Joel,
Got the point.
Saved much time involved in manual work.


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
Creating a Drop Down List with Step by Step Instructions for 2007 remarkable Excel Worksheet Functions 2 March 22nd 09 04:36 AM
Need step by step to add invoice numbering to excel template rmt New Users to Excel 4 July 6th 08 11:45 PM
Can anyone povide step by step instructions on how to do the follo Daniel Bunt Excel Discussion (Misc queries) 6 January 26th 07 12:58 PM
What is the step-by-step procedure for making a data list? Bobgolfs56 Excel Discussion (Misc queries) 1 April 23rd 05 02:19 PM
I need step by step instructions to create a macro for 10 imbedde. diana Excel Worksheet Functions 3 January 31st 05 01:56 AM


All times are GMT +1. The time now is 08:15 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"