Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
tks mike it does work
"Mike Fogleman" wrote: Watch for word wrap on my Set DestRng = line. It was a little longer than the other lines. Mike F "Mike Fogleman" wrote in message ... Stratis: This will do basically the same method, but will now use any number of columns in your original data and place it in the next column following your data. Since Excel only has 256 columns, this code will limit you to 128 columns of original data. If you think you will exceed this, and/or 65,536 rows, then we will need some more code to test for these limits. Sub CopyTimes() Dim LRow As Long, LCol As Long Dim c As Range, SourceRng As Range, DestRng As Range, CopyRng As Range Dim CopyNum As Long, CopyFrom As Long, CopyTo As Long LRow = Cells(Rows.Count, "A").End(xlUp).Row LCol = Range("A1").CurrentRegion.Columns.Count Set SourceRng = Range("A1:A" & LRow) CopyFrom = 1 For Each c In SourceRng CopyNum = c.Offset(0, LCol - 1).Value CopyTo = CopyFrom + CopyNum - 1 Set DestRng = Range((Cells(CopyFrom, LCol + 1)), (Cells(CopyTo, (LCol * 2) - 1))) Set CopyRng = Range((Cells(c.Row, c.Column)), (Cells(c.Row, LCol - 1))) DestRng = CopyRng.Value CopyFrom = CopyFrom + CopyNum Next c End Sub Mike F "stratis" wrote in message ... mike thanks it worked. I am not familiar with allof this so maybe you can bear with me do you know if I had 2 or more colums to generate what could be the changes to do I tried changing the desitnation string to D but gave me error a b 2 a b a b "Mike Fogleman" wrote: Stratis, You can try this. It worked in my test sample. It will put the copies in column C and assumes your Original is in Columns A:B. It also assumes the data starts in row 1 (no header). You can adjust the code accordingly and delete columns A:B when done if you wish, or leave them intact. Sub CopyTimes() Dim LRow As Long Dim c As Range, SourceRng As Range, DestRng As Range Dim CopyNum As Long, CopyFrom As Long, CopyTo As Long LRow = Cells(Rows.Count, "A").End(xlUp).Row Set SourceRng = Range("A1:A" & LRow) CopyFrom = 1 For Each c In SourceRng CopyNum = c.Offset(0, 1).Value CopyTo = CopyFrom + CopyNum - 1 Set DestRng = Range("C" & CopyFrom & ":C" & CopyTo) DestRng = c.Value CopyFrom = CopyFrom + CopyNum Next c End Sub Mike F "stratis" wrote in message ... If I have an spreadsheet of the type position 1 2 position 2 3 etc is there a macro I can generate position 1 position 1 position2 position2 position2 etc |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to generate same event (has 2 possible outcomes) 200 times? | Excel Discussion (Misc queries) | |||
Is Multi click Event possible? | Excel Discussion (Misc queries) | |||
generate a list from a single row of data | Excel Discussion (Misc queries) | |||
Multi rows to single row | Excel Discussion (Misc queries) | |||
Generate an event when a cell is pressed | Excel Programming |