Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Macro Help - Insert row/copy based on criteria

I need a macro
that will insert a number of rows
based on the number of months between a start and end date
and then copy the information in the above row to the new rows.

The records are over 8,350.. so ill also need some idea how to get it to
stop when it fills the worksheet so i can transfer those into another workbook
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Macro Help - Insert row/copy based on criteria

What version of Excel are you using?


"Katerinia" wrote in message
...
I need a macro
that will insert a number of rows
based on the number of months between a start and end date
and then copy the information in the above row to the new rows.

The records are over 8,350.. so ill also need some idea how to get it to
stop when it fills the worksheet so i can transfer those into another
workbook



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Macro Help - Insert row/copy based on criteria

If you have xl2007 or later, you probably do not have to worry about the
number of rows, but I included a cut off just in case.

Sub standard()
Dim c As Range, rng As Range, a As Long
Dim sh As Worksheet, lr As Long
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:A" & lr)
For Each c In rng
If Not c Is Nothing Then
a = DateDiff("m", Range("A" & c.Row).Value, Range("B" &
c.Row).Value)
If a 1 Then
c.Offset(1, 0).Resize(a, 1).EntireRow.Insert
End If
If c.Row = 65520 Then
MsgBox "Less than 16 rows available, Procedure will
teminate"
Exit Sub
End If
End If
Next
End Sub



"Katerinia" wrote in message
...
I need a macro
that will insert a number of rows
based on the number of months between a start and end date
and then copy the information in the above row to the new rows.

The records are over 8,350.. so ill also need some idea how to get it to
stop when it fills the worksheet so i can transfer those into another
workbook



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Macro Help - Insert row/copy based on criteria

P.S.

If your start date is not in column A and your end date is not in column B
then you will need to change the column reference in this line:

Set rng = sh.Range("A2:A" & lr)

And this line:

a = DateDiff("m", Range("A" & c.Row).Value, Range("B" & c.Row).Value)

The code was based on the assumption that col A contains the start Date and
Col B contains the end date. The DateDiff function requires the earlier
date to be the argument before the later date or you will get a negative
result and the code will fail.





"JLGWhiz" wrote in message
...
If you have xl2007 or later, you probably do not have to worry about the
number of rows, but I included a cut off just in case.

Sub standard()
Dim c As Range, rng As Range, a As Long
Dim sh As Worksheet, lr As Long
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:A" & lr)
For Each c In rng
If Not c Is Nothing Then
a = DateDiff("m", Range("A" & c.Row).Value, Range("B" &
c.Row).Value)
If a 1 Then
c.Offset(1, 0).Resize(a, 1).EntireRow.Insert
End If
If c.Row = 65520 Then
MsgBox "Less than 16 rows available, Procedure will
teminate"
Exit Sub
End If
End If
Next
End Sub



"Katerinia" wrote in message
...
I need a macro
that will insert a number of rows
based on the number of months between a start and end date
and then copy the information in the above row to the new rows.

The records are over 8,350.. so ill also need some idea how to get it to
stop when it fills the worksheet so i can transfer those into another
workbook





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
Excel macro to copy row from one tab to another based on certain criteria DavidSchardien Excel Programming 2 March 29th 10 09:08 PM
insert rows based on criteria MP Excel Discussion (Misc queries) 0 December 3rd 08 06:36 PM
Create a Macro to Insert a number into a column based on criteria [email protected] Excel Programming 3 August 8th 07 06:14 PM
Macro or formula to copy data based on criteria MT[_2_] Excel Programming 1 September 5th 05 03:03 PM


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