Auto Insert New Line

mmmarty

Board Regular
Joined
Oct 23, 2004
Messages
79
Can someone tell me where I'm astray on this.
This small script peers down column B:B looking for instances of the word "~AutoLine".
If there is only 1 empty cell in B:B above the word "~AutoLine" then an entire row is self inserted forcing the "~AutoLine" line to move down by one row.

The good part is the newly inserted row copies the contents of the last line, but it also copies the trigger word in B:B "~AutoLine".

Is there a way to clear just this one NEW instance in the B:B cell containing the word "~AutoLine" ??


Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range, Cntr As Integer

If Target.Cells.Count > 2 Then Exit Sub
If Target.Column <> 2 Then Exit Sub
On Error Resume Next

With Range("B:B")
Set Rng = .Find(what:="~AutoLine", LookIn:=xlFormulas)

If Not Rng Is Nothing Then

Do
Cntr = Cntr + 1
If Not IsEmpty(Rng.Offset(-1)) Then

Rng.EntireRow.Copy

Rng.EntireRow.Insert Shift:=xlDown

Rng.EntireRow.PasteSpecial
End If

Set Rng = .FindNext(Rng)
If Rng Is Nothing Then Exit Do
Loop Until Cntr >= 30

End If
End With


End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
It is getting near the end of the week so bear with me.

I think you want someting like this in your loop

Code:
ActiveSheet.Cells(rng.Row, 2).ClearContents
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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