Macro to insert lines

L

Linda

I'm trying to write a marco to search for a certain value in column A. When
the value is found, I want to insert a blank line above it. Once this is
done, I want to repeat the process for the entire worksheet.

Here's the macro I wrote. The problem is that is keeps inserting the blank
row at the top of the worksheet. It doesn't move to the next value. I'm not
sure how to write the code for this.

Sub PV1insertblank()
'
' PV1insertblank Macro
' Macro recorded 4/10/2009 by krauli20
'
' Keyboard Shortcut: Ctrl+q
'
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Find(What:="PV1", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
Selection.Interior.ColorIndex = xlNone
End Sub
Sub Macro6()
'
' Macro6 Macro
' Macro recorded 4/10/2009 by krauli20
'

'
End Sub
 
D

Don Guillett

Try this instead
Sub insertrows()
For i = Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
If UCase(Cells(i, 1)) = "PV1" Then Rows(i).Insert
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top