Insert worksheet range every time cell value changes

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!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top