Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default how to combine each record into a range?

Hi Chip,
Thanks a lot!
pemt

"Chip Pearson" wrote:

Try some code like the following.


Sub AAA()

Dim R As Range
Dim Dest As Range
Dim CurrVal As Long
Dim Upper As Long
Dim Lower As Long
Dim LastRow As Long

Set Dest = Sheets(2).Range("A1") '<<<< CHANGE
Set R = Worksheets(1).Range("A1") '<<< CHANGE
CurrVal = R(1, 2).Value
Upper = R(1, 1).Value
Lower = R(1, 1).Value

For Each R In Worksheets(1).Range("A1:A26") '<<< CHANGE
If R(1, 2).Value < CurrVal Then
Dest(1, 1).Value = Lower
Dest(1, 2).Value = Upper
Dest(1, 3).Value = CurrVal
Lower = R(1, 1).Value
CurrVal = R(1, 2).Value
Set Dest = Dest(2, 1)
End If
Upper = R(1, 1).Value
Next R

End Sub

Change the values marked with <<<< to the appropriate values. R should
be set to the first cell that is to be examined. The For Each loop
should be set to the entire range that will be examined. Dest should
be set to the destination of the new records.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com





On Tue, 23 Mar 2010 11:13:01 -0700, pemt
wrote:

how to combine each record into a range?
Table1
Day Value
1 0
2 0
3 0
4 1
5 1
6 1
7 0
8 0
9 0
10 0
11 1
12 1
13 0
14 1
15 0
16 0
17 1
18 1
19 0
20 1
. .
. .
. .
1000 1

how to covert the above table into:
DayStart DayEnd Value
1 3 0
4 6 1
7 10 0
11 12 1
13 13 0
14 14 1
15 16 0
17 18 1
19 19 0
...

thanks,

pemt


.

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
Combine multiple columns and rows for one record into one row. Bowtie63 Excel Discussion (Misc queries) 2 February 16th 08 04:20 AM
Using a listbox to show every unique record in a range [email protected] Excel Worksheet Functions 4 July 19th 06 06:04 PM
combine 2 rows into 1 record GreenPower Excel Discussion (Misc queries) 1 December 30th 05 04:10 PM
Can I combine 2 rows to make one record? GreenPower Excel Discussion (Misc queries) 3 September 28th 05 09:04 PM
Extra Record in Data Range Bill Gates Excel Discussion (Misc queries) 2 March 31st 05 08:21 PM


All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"