Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to create uniform ranges?

Hi everybody,

I'm dealing with following problem: There are 3 data series in each
column (A, B, C). Column A represents distance (between 10 m and 100 m,
in other words randomly distributed). Question: Does anybody know how
it can be arranged by every 100 m (sum of continuous rows such as A1+A2+
etc. if the cell is equal to 100 then it should check next rows, even
several rows). B and C parameters which depend on A; B and C parameters
should be averaged accordingly to summed cells of A.

Example:

A B C
100 6.1 2.8
100 7.5 2.3
20 6.1 3.7
14 6.1 6.7
66 6.1 3.1
34 7 3.1
66 7 2.3


Desired Output:

A B C
100 6.1 2.8
100 7.5 2.3
100 6.1 4.5
(20+14+66) average(6.1,6.1,6.1) average(3.7,6.7,3.1)
......

......


I will appreciate any opinion, suggestion on how to create macro using
VBA excel for this problem.



Thanks a lot in advance,
Jamshid

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default How to create uniform ranges?

Hi, I haven't tested this, but something along these lines should get
you pretty close to what you are looking for if I understand you
correctly. If not we can try again--Lonnie M.

Sub Test100()
Dim CountData&, X&, SumEnd&, C&, Aholder@, Bholder@, Cholder@
CountData = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
'SumEnd represents the row value to place 100 values
SumEnd = CountData + 1
For X = 1 To CountData
'Assuming A2 is the first data cell
If Aholder < 100 Then
Aholder = Aholder + Cells(X + 1, 1)
Bholder = Bholder + Cells(X + 1, 2)
Cholder = Cholder + Cells(X + 1, 3)
C = C + 1
End If
If Aholder = 100 Then
SumEnd = SumEnd + 1
Cells(SumEnd, 1) = Aholder
Cells(SumEnd, 2) = Bholder / C
Cells(SumEnd, 3) = Cholder / C
Aholder = 0
Bholder = 0
Cholder = 0
C = 0
End If
Next X
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default How to create uniform ranges?

Hi, I haven't tested this but it should get you in the neighborhood:
'################################################# ########
Sub Test100()
Dim CountData&, X&, SumEnd&, C&, Aholder@, Bholder@, Cholder@
CountData = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
'SumEnd represents the row value to place 100 values
SumEnd = CountData + 1
For X = 1 To CountData
'Assuming A2 is the first data cell
If Aholder < 100 Then
Aholder = Aholder + Cells(X + 1, 1)
Bholder = Bholder + Cells(X + 1, 2)
Cholder = Cholder + Cells(X + 1, 3)
C = C + 1
End If
If Aholder = 100 Then
SumEnd = SumEnd + 1
Cells(SumEnd, 1) = Aholder
Cells(SumEnd, 2) = Bholder / C
Cells(SumEnd, 3) = Cholder / C
Aholder = 0
Bholder = 0
Cholder = 0
C = 0
End If
Next X
End Sub
'################################################# ########
HTH--Lonnie M.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default How to create uniform ranges?

Hi

This copies the data over to columns E:F so that you can check it

Dim i As Long, r As Long, nr As Long
Sub copyData()
Dim tot As Integer, n As Integer
Dim x As Double, y As Double
Range("A2").Select
nr = ActiveCell.CurrentRegion.Rows.Count
For i = 2 To nr
n = 1
If Cells(i, 1) = 100 Then
Range(Cells(i, 5), Cells(i, 7)).Value = _
Range(Cells(i, 1), Cells(i, 3)).Value
ElseIf Cells(i, 1) < 100 Then

tot = Cells(i, 1).Value
x = Cells(i, 2).Value
y = Cells(i, 3).Value
Do While tot < 100
i = i + 1
n = n + 1
tot = tot + Cells(i, 1).Value
x = x + Cells(i, 2).Value
y = y + Cells(i, 3).Value
Loop
Cells(i, 5) = tot: Cells(i, 6) = x / n
Cells(i, 7) = y / n
tot = 0: x = 0: y = 0: n = 0
End If
Next i

End Sub


Regards
Peter

"Jamshid" wrote:

Hi everybody,

I'm dealing with following problem: There are 3 data series in each
column (A, B, C). Column A represents distance (between 10 m and 100 m,
in other words randomly distributed). Question: Does anybody know how
it can be arranged by every 100 m (sum of continuous rows such as A1+A2+
etc. if the cell is equal to 100 then it should check next rows, even
several rows). B and C parameters which depend on A; B and C parameters
should be averaged accordingly to summed cells of A.

Example:

A B C
100 6.1 2.8
100 7.5 2.3
20 6.1 3.7
14 6.1 6.7
66 6.1 3.1
34 7 3.1
66 7 2.3


Desired Output:

A B C
100 6.1 2.8
100 7.5 2.3
100 6.1 4.5
(20+14+66) average(6.1,6.1,6.1) average(3.7,6.7,3.1)
......

......


I will appreciate any opinion, suggestion on how to create macro using
VBA excel for this problem.



Thanks a lot in advance,
Jamshid


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default How to create uniform ranges?

Hi Peter,
I have found that the following can get a little quirky when data has
been removed or formats have been applied:
ActiveCell.CurrentRegion.Rows.Count

This method provided by Tom Ogilvy will give you a more reliable rows
count:
ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

Have a good one :)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to create uniform ranges?

Thank you Peter for providing second solution,



Best Regards,
Jamshid



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to create uniform ranges?


Thanks a lot Lonnie, you nailed it. even some cases (few cases) greater
than 100 but for most of the cases 100. You gave very good idea.

Once again, thank you.

Best wishes :),
Jamshid



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Create 3 Ranges in 1 Arlen Excel Discussion (Misc queries) 4 August 12th 08 05:36 PM
how can i make a uniform timetable? student101 Excel Discussion (Misc queries) 1 March 15th 05 06:39 AM
Concatenate and make uniform JYowler Excel Worksheet Functions 2 November 2nd 04 10:50 PM
Concatenate and make uniform JYowler Excel Worksheet Functions 0 November 2nd 04 06:19 PM
adding uniform footers Jamie Martin Excel Programming 1 July 10th 03 03:59 AM


All times are GMT +1. The time now is 05:42 AM.

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"