Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jbg jbg is offline
external usenet poster
 
Posts: 16
Default Insert Row based on count and copy range to inserted rows

Hello,
I am working with the following code that is working fine, I just need some
help to make an adjustment to it as I can't figure it out. At the time of
'Names copied down to the inserted rows' I would like it to copy the values
from the range iRow "A" to iRow "W" to the inserted row instead of just iRow
"A" as it is now.

Thanks for your help.

Sub InsertRowsBasedOnCount()
Dim wks As Worksheet
Dim iRow As Long
Dim HowManyRows As Variant
Dim FirstRow As Long
Dim LastRow As Long

Set wks = Worksheets("Data resolution category")
With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "X").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
HowManyRows = .Cells(iRow, "X").Value
If IsNumeric(HowManyRows) Then
'some minor testing
If HowManyRows 1 _
And HowManyRows < 100 Then
.Rows(iRow + 1).Resize(HowManyRows - 1).Insert
'Names copied down to the inserted rows
.Cells(iRow + 1, "A").Resize(HowManyRows - 1).Value _
= .Cells(iRow, "A").Value

End If
End If
Next iRow
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Insert Row based on count and copy range to inserted rows

Try a change to this portion:
.Cells(iRow + 1, "A").Resize(HowManyRows - 1).Value _
= .Cells(iRow, "A").Value

to:
.Cells(iRow + 1, "A").Resize(HowManyRows - 1, 23).Value _
= .Cells(iRow, "A").Resize(1, 23).Value

The 23 (in both spots!) is the number of columns A:W.

JBG wrote:

Hello,
I am working with the following code that is working fine, I just need some
help to make an adjustment to it as I can't figure it out. At the time of
'Names copied down to the inserted rows' I would like it to copy the values
from the range iRow "A" to iRow "W" to the inserted row instead of just iRow
"A" as it is now.

Thanks for your help.

Sub InsertRowsBasedOnCount()
Dim wks As Worksheet
Dim iRow As Long
Dim HowManyRows As Variant
Dim FirstRow As Long
Dim LastRow As Long

Set wks = Worksheets("Data resolution category")
With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "X").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
HowManyRows = .Cells(iRow, "X").Value
If IsNumeric(HowManyRows) Then
'some minor testing
If HowManyRows 1 _
And HowManyRows < 100 Then
.Rows(iRow + 1).Resize(HowManyRows - 1).Insert
'Names copied down to the inserted rows
.Cells(iRow + 1, "A").Resize(HowManyRows - 1).Value _
= .Cells(iRow, "A").Value

End If
End If
Next iRow
End With

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
jbg jbg is offline
external usenet poster
 
Posts: 16
Default Insert Row based on count and copy range to inserted rows

Thanks Dave. That worked perfectly.

"Dave Peterson" wrote:

Try a change to this portion:
.Cells(iRow + 1, "A").Resize(HowManyRows - 1).Value _
= .Cells(iRow, "A").Value

to:
.Cells(iRow + 1, "A").Resize(HowManyRows - 1, 23).Value _
= .Cells(iRow, "A").Resize(1, 23).Value

The 23 (in both spots!) is the number of columns A:W.

JBG wrote:

Hello,
I am working with the following code that is working fine, I just need some
help to make an adjustment to it as I can't figure it out. At the time of
'Names copied down to the inserted rows' I would like it to copy the values
from the range iRow "A" to iRow "W" to the inserted row instead of just iRow
"A" as it is now.

Thanks for your help.

Sub InsertRowsBasedOnCount()
Dim wks As Worksheet
Dim iRow As Long
Dim HowManyRows As Variant
Dim FirstRow As Long
Dim LastRow As Long

Set wks = Worksheets("Data resolution category")
With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "X").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
HowManyRows = .Cells(iRow, "X").Value
If IsNumeric(HowManyRows) Then
'some minor testing
If HowManyRows 1 _
And HowManyRows < 100 Then
.Rows(iRow + 1).Resize(HowManyRows - 1).Insert
'Names copied down to the inserted rows
.Cells(iRow + 1, "A").Resize(HowManyRows - 1).Value _
= .Cells(iRow, "A").Value

End If
End If
Next iRow
End With

End Sub


--

Dave Peterson

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
Need Macro- Insert rows based on dates and copy info from that row Katerinia Excel Discussion (Misc queries) 1 April 6th 10 08:02 PM
Insert rows and keep merged cells in the inserted row Buggelsgaard Excel Discussion (Misc queries) 1 August 27th 08 06:33 PM
copy rows based on conditions and insert them into another sheet... [email protected] Excel Programming 3 November 25th 07 10:22 PM
Set new range based on rng.Offset(rng.Rows.Count, 0).Resize(1, 1) Keith Excel Programming 2 January 7th 07 08:35 PM
automatically insert formula when new rows are inserted BLUEJAY Excel Worksheet Functions 0 April 27th 06 10:28 AM


All times are GMT +1. The time now is 10:53 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"