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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,991
Messages
5,834,769
Members
430,319
Latest member
Excelhelppll

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
Top