Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Combine multiple columns and rows for one record into one row. | Excel Discussion (Misc queries) | |||
Using a listbox to show every unique record in a range | Excel Worksheet Functions | |||
combine 2 rows into 1 record | Excel Discussion (Misc queries) | |||
Can I combine 2 rows to make one record? | Excel Discussion (Misc queries) | |||
Extra Record in Data Range | Excel Discussion (Misc queries) |