ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro to insert lines (https://www.excelbanter.com/excel-worksheet-functions/227336-macro-insert-lines.html)

LINDA

Macro to insert lines
 
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


Don Guillett

Macro to insert lines
 
Look in the vba help index for FINDNEXT. There is a good example


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Linda" wrote in message
...
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



Don Guillett

Macro to insert lines
 
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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Linda" wrote in message
...
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




All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com