This could should work
Sub insert()
i = 1
Do
If Range("A" & i).Value = "" Then Exit Do
If Range("A" & i + 1).Value - Range("A" & i).Value > 1 Then
m = Range("A" & i + 1).Value - Range("A" & i).Value
Range("A" & i + 1).Select
l = i + 1
For k = 1 To m - 1
Range("A" & l).Select
Selection.EntireRow.insert
Range("A" & l).Value = Range("A" & (l - 1)).Value + 1
l = l + 1
Next k
Else
End If
i = i + 1
Loop
End Sub
-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Dustin
Sent: 20 April 2009 22:57
To: MS EXCEL AND VBA MACROS
Subject: $$Excel-Macros$$ Need Help with Macro, Insert Rows based on another
cell's value
Hello! I am new to this group, and new to VBA in general, so I would
appreciate any insight / explanations into this =)
Here is the situation:
There will be raw data in the form of a spreadsheet which is in
chronological order, though not in steps of 1. So for instance, Column A
could be numbered 1,2,3,4,5,15,16,45 ...etc. There will also be
corresponding data in columns following it. The following is an example of
what it could look like (Columns A and B, though there will be many more
columns)
100 this is 100
101 this is 101
102 this is 102
103 this is 103
104 this is 104
110 this is 110
...
What I need this macro to do, is to insert a row where the order is not in
steps of 1, and then copy the appropriate number into that new row. Thus:
100 this is 100
101 this is 101
102 this is 102
103 this is 103
104 this is 104
105
106
107
108
109
110 this is 110
...
I would super appreciate help with this!
Thanks!!
Dustin
--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
To post to this group, send email to [email protected]
If you find any spam message in the group, please send an email to:
Ayush Jain @ [email protected] or
Ashish Jain @ [email protected]
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---