Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Inserting and copying Rows based on a variable

I have a very long spreadsheet that has a beginning year in column A and the
ending year in column B. Column C (which currently has no data in it) =
Specific Year. The rest of the row is specific information that applies to
each year in the range. I need to insert the number of rows based on the
number of years in the range, i.e Column A = 2004, Column B=2006. I would
need to insert 3 rows and add each specific year in the range to column C.
Assuming the data starts in Row 2 and Column A = 2004, Column B = 2006,
Column C = " ", Column D thru Column AY has data. The resulting data should
be: Row 3: Column A = " ", Column B = " ", Column C = 2004, Column D thru AY
= Row 2 data Column D thru AY. Row 4 would be the same as row 3 except Column
C would index to 2005. I appreciate anyone out there can help me out with a
Macro.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Inserting and copying Rows based on a variable

Hi Darwin

Try and feedback the below macro which works on the activesheet.

Sub MyMacro()
Dim lngRow As Long, intTemp As Integer
lngRow = 2
Do
If Range("A" & lngRow) < "" Then
For intTemp = Range("A" & lngRow) To Range("B" & lngRow)
Rows(lngRow + 1).Insert: Range("C" & lngRow + 1) = intTemp
Range("D" & lngRow & ":AY" & lngRow).Copy _
Range("D" & lngRow + 1 & ":AY" & lngRow + 1)
lngRow = lngRow + 1
Next
End If
lngRow = lngRow + 1
Loop Until lngRow Cells(Rows.Count, "A").End(xlUp).Row
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Darwin" wrote:

I have a very long spreadsheet that has a beginning year in column A and the
ending year in column B. Column C (which currently has no data in it) =
Specific Year. The rest of the row is specific information that applies to
each year in the range. I need to insert the number of rows based on the
number of years in the range, i.e Column A = 2004, Column B=2006. I would
need to insert 3 rows and add each specific year in the range to column C.
Assuming the data starts in Row 2 and Column A = 2004, Column B = 2006,
Column C = " ", Column D thru Column AY has data. The resulting data should
be: Row 3: Column A = " ", Column B = " ", Column C = 2004, Column D thru AY
= Row 2 data Column D thru AY. Row 4 would be the same as row 3 except Column
C would index to 2005. I appreciate anyone out there can help me out with a
Macro.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Inserting and copying Rows based on a variable

Jacob

The Macro worked like a dream. It saved me many hours of clicking and
inserting. I appreciate the help.

Darwin

"Jacob Skaria" wrote:

Hi Darwin

Try and feedback the below macro which works on the activesheet.

Sub MyMacro()
Dim lngRow As Long, intTemp As Integer
lngRow = 2
Do
If Range("A" & lngRow) < "" Then
For intTemp = Range("A" & lngRow) To Range("B" & lngRow)
Rows(lngRow + 1).Insert: Range("C" & lngRow + 1) = intTemp
Range("D" & lngRow & ":AY" & lngRow).Copy _
Range("D" & lngRow + 1 & ":AY" & lngRow + 1)
lngRow = lngRow + 1
Next
End If
lngRow = lngRow + 1
Loop Until lngRow Cells(Rows.Count, "A").End(xlUp).Row
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Darwin" wrote:

I have a very long spreadsheet that has a beginning year in column A and the
ending year in column B. Column C (which currently has no data in it) =
Specific Year. The rest of the row is specific information that applies to
each year in the range. I need to insert the number of rows based on the
number of years in the range, i.e Column A = 2004, Column B=2006. I would
need to insert 3 rows and add each specific year in the range to column C.
Assuming the data starts in Row 2 and Column A = 2004, Column B = 2006,
Column C = " ", Column D thru Column AY has data. The resulting data should
be: Row 3: Column A = " ", Column B = " ", Column C = 2004, Column D thru AY
= Row 2 data Column D thru AY. Row 4 would be the same as row 3 except Column
C would index to 2005. I appreciate anyone out there can help me out with a
Macro.

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
Copying & Inserting Rows w/o Affecting other Rows Etc. LRay67 Excel Worksheet Functions 1 October 22nd 08 02:10 AM
copying formulas when inserting new rows Steve M[_4_] Excel Discussion (Misc queries) 7 September 8th 08 02:55 PM
need help please inserting multiple rows based on cell value then copying to data sheet [email protected] Excel Worksheet Functions 1 July 1st 07 08:44 PM
Inserting rows at variable points Janet H[_2_] Excel Programming 4 September 8th 05 08:27 PM
Inserting Variable Number of Rows bundyloco[_7_] Excel Programming 2 August 29th 05 11:25 AM


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

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"