cameron.beyers
New Member
- Joined
- May 30, 2012
- Messages
- 2
Hi all,
I have a worksheet with Columns A:U. For these columns I have thousands of rows of data. I want to insert a copied range from another worksheet every time the value in Column E changes. Column E is a station ID and doesn't repeat on a fixed increment.
Col E
10714
10714
10714
11523
12434
12434
etc....
Here is the code I have so far. It only inserts the copied range for the very first station ID.
Sub Insert_dummy()
'
' Insert_dummy Macro
'
Dim r As Long, mcol As String, i As Long
' find last used cell in Column A
r = Cells(Rows.Count, "E").End(xlDown).Row
' get value of last used cell in column E
mcol = Cells(r, 1).Value
' insert rows by looping from bottom
For i = r To 2 Step -1
If Cells(i, 1).Value <> mcol Then
mcol = Cells(i, 1).Value
Sheets("Sheet1").Select
Range("A2:U117").Select
Selection.Copy
Sheets("Basin 8A").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End If
Next i
End Sub
Any help would be greatly appreciated.
Thanks!
I have a worksheet with Columns A:U. For these columns I have thousands of rows of data. I want to insert a copied range from another worksheet every time the value in Column E changes. Column E is a station ID and doesn't repeat on a fixed increment.
Col E
10714
10714
10714
11523
12434
12434
etc....
Here is the code I have so far. It only inserts the copied range for the very first station ID.
Sub Insert_dummy()
'
' Insert_dummy Macro
'
Dim r As Long, mcol As String, i As Long
' find last used cell in Column A
r = Cells(Rows.Count, "E").End(xlDown).Row
' get value of last used cell in column E
mcol = Cells(r, 1).Value
' insert rows by looping from bottom
For i = r To 2 Step -1
If Cells(i, 1).Value <> mcol Then
mcol = Cells(i, 1).Value
Sheets("Sheet1").Select
Range("A2:U117").Select
Selection.Copy
Sheets("Basin 8A").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End If
Next i
End Sub
Any help would be greatly appreciated.
Thanks!