Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
I am trying to insert and copy a number of rows according to a cell value. From the data below I would ignore all the 1's and if the number is 1, eg 4 then insert 3 rows (4-1) and copy the data, so result would be Londontt,4 Londontt,4 Londontt,4 Londontt,4 Orginal data below London54 , 1 London44,1 London333,2 London77,1 London99, 5 London33,1 I can use the code below to loop. Do Until IsEmpty(ActiveCell) = True If ActiveCell.Value < 1 Then ActiveCell.EntireRow.Select active.cell.Select Selection.Insert GoTo Continue End If ActiveCell.Offset(1, 0).Select Loop Continue: Thanks, Ed |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 13, 8:05*pm, Ed Peters wrote:
Hi all, I am trying to insert and copy a number of rows according to a cell value. From the data below I would ignore all the 1's *and if the number is1, eg 4 then insert 3 rows (4-1) and copy the data, so result would be Londontt,4 Londontt,4 Londontt,4 Londontt,4 Orginal data below London54 , 1 London44,1 London333,2 London77,1 London99, 5 London33,1 I can use the code below to loop. Do Until IsEmpty(ActiveCell) = True If ActiveCell.Value < 1 Then * * ActiveCell.EntireRow.Select * * active.cell.Select * * *Selection.Insert * * *GoTo Continue End If ActiveCell.Offset(1, 0).Select *Loop Continue: Thanks, Ed Noticied my origial data did not include the one row Londontt,4 so would be London54 , 1 London44,1 London333,2 Londontt,4 London77,1 London99, 5 London33,1 Ed |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't really follow your request but does this do what you want:
Sub Trial() Dim LastRow As Long Dim x As Long Dim I Application.ScreenUpdating = False LastRow = Cells(Rows.Count, 1).End(xlUp).Row For x = LastRow To 1 Step -1 I = Right(Cells(x, 1).Value, 1) If IsNumeric(I) Then If I 1 Then Cells(x, 1).Resize(I - 1, 1).EntireRow.Insert End If End If Next x LastRow = Cells(Rows.Count, 1).End(xlUp).Row For x = LastRow To 2 Step -1 If Cells(x, 1).Value = "" Then _ Cells(x, 1).Value = Cells(x + 1, 1).Value Next x Application.ScreenUpdating = True End Sub Assumes that the data starts in A1 and has no data under the data given. Try it on a *COPY* of your data. -- HTH Sandy In Perth, the ancient capital of Scotland and the crowning place of kings Replace @mailinator.com with @tiscali.co.uk "Ed Peters" wrote in message ... On Feb 13, 8:05 pm, Ed Peters wrote: Hi all, I am trying to insert and copy a number of rows according to a cell value. From the data below I would ignore all the 1's and if the number is1, eg 4 then insert 3 rows (4-1) and copy the data, so result would be Londontt,4 Londontt,4 Londontt,4 Londontt,4 Orginal data below London54 , 1 London44,1 London333,2 London77,1 London99, 5 London33,1 I can use the code below to loop. Do Until IsEmpty(ActiveCell) = True If ActiveCell.Value < 1 Then ActiveCell.EntireRow.Select active.cell.Select Selection.Insert GoTo Continue End If ActiveCell.Offset(1, 0).Select Loop Continue: Thanks, Ed Noticied my origial data did not include the one row Londontt,4 so would be London54 , 1 London44,1 London333,2 Londontt,4 London77,1 London99, 5 London33,1 Ed |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 13, 9:09*pm, "Sandy Mann" wrote:
I don't really follow your request but does this do what you want: Sub Trial() * * Dim LastRow As Long * * Dim x As Long * * Dim I * * Application.ScreenUpdating = False * * LastRow = Cells(Rows.Count, 1).End(xlUp).Row * * For x = LastRow To 1 Step -1 * * * * I = Right(Cells(x, 1).Value, 1) * * * * If IsNumeric(I) Then * * * * * * If I 1 Then * * * * * * * * Cells(x, 1).Resize(I - 1, 1).EntireRow.Insert * * * * * * End If * * * * End If * * Next x * * LastRow = Cells(Rows.Count, 1).End(xlUp).Row * * For x = LastRow To 2 Step -1 * * * * If Cells(x, 1).Value = "" Then _ * * * * * * Cells(x, 1).Value = Cells(x + 1, 1).Value * * Next x * * Application.ScreenUpdating = True End Sub Assumes that the data starts in A1 and has no data under the data given. Try it on a *COPY* of your data. -- HTH Sandy In Perth, the ancient capital of Scotland and the crowning place of kings Replace @mailinator.com with @tiscali.co.uk "Ed Peters" wrote in message ... On Feb 13, 8:05 pm, Ed Peters wrote: Hi all, I am trying to insert and copy a number of rows according to a cell value. From the data below I would ignore all the 1's and if the number is1, eg 4 then insert 3 rows (4-1) and copy the data, so result would be Londontt,4 Londontt,4 Londontt,4 Londontt,4 Orginal data below London54 , 1 London44,1 London333,2 London77,1 London99, 5 London33,1 I can use the code below to loop. Do Until IsEmpty(ActiveCell) = True If ActiveCell.Value < 1 Then ActiveCell.EntireRow.Select active.cell.Select Selection.Insert GoTo Continue End If ActiveCell.Offset(1, 0).Select Loop Continue: Thanks, Ed Noticied my origial data did not include the one row Londontt,4 so would be London54 , 1 London44,1 London333,2 Londontt,4 London77,1 London99, 5 London33,1 Ed- Hide quoted text - - Show quoted text - Yes thanks , it got me on the right direction. Ed |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
find number & insert rows | Excel Programming | |||
Insert a number of rows based on a value in a cell on active row | Excel Programming | |||
Insert a number of rows based on a value in a cell on active row | Excel Discussion (Misc queries) | |||
Insert a number of rows based on a value in a cell on active row | Excel Worksheet Functions | |||
insert 'x' number of rows??? | Excel Programming |