ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   insert a line via macro (https://www.excelbanter.com/excel-discussion-misc-queries/192833-insert-line-via-macro.html)

Don

insert a line via macro
 
thanks for the help in the past.

I have a spreadsheet that I want to find a statement like "section 1" that
could change the line it is on then backup two line and insert a line or
maybe 5 lines.

I have tried to record a macro but it keeps selecting the line and I thought
there was an offset command in VB?

Columns("A:A").Select
Selection.Find(What:="Section 1", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("A8").Select
Selection.EntireRow.Insert

Roger Govier[_3_]

insert a line via macro
 
Hi Don

You are selecting A8 each time before inserting.
Change code to

Columns("A:A").Select
Selection.Find(What:="Section 1", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.EntireRow.Insert


--
Regards
Roger Govier

"Don" wrote in message
...
thanks for the help in the past.

I have a spreadsheet that I want to find a statement like "section 1" that
could change the line it is on then backup two line and insert a line or
maybe 5 lines.

I have tried to record a macro but it keeps selecting the line and I
thought
there was an offset command in VB?

Columns("A:A").Select
Selection.Find(What:="Section 1", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("A8").Select
Selection.EntireRow.Insert



Don

insert a line via macro
 
Thanks Roger, I will give it a shot. appreciate the help

"Roger Govier" wrote:

Hi Don

You are selecting A8 each time before inserting.
Change code to

Columns("A:A").Select
Selection.Find(What:="Section 1", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.EntireRow.Insert


--
Regards
Roger Govier

"Don" wrote in message
...
thanks for the help in the past.

I have a spreadsheet that I want to find a statement like "section 1" that
could change the line it is on then backup two line and insert a line or
maybe 5 lines.

I have tried to record a macro but it keeps selecting the line and I
thought
there was an offset command in VB?

Columns("A:A").Select
Selection.Find(What:="Section 1", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("A8").Select
Selection.EntireRow.Insert




Gord Dibben

insert a line via macro
 
If you use the Relative References button when recording you should get the
Offset code.


Gord Dibben MS Excel MVP

On Fri, 27 Jun 2008 04:39:01 -0700, Don wrote:

Thanks Roger, I will give it a shot. appreciate the help

"Roger Govier" wrote:

Hi Don

You are selecting A8 each time before inserting.
Change code to

Columns("A:A").Select
Selection.Find(What:="Section 1", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.EntireRow.Insert


--
Regards
Roger Govier

"Don" wrote in message
...
thanks for the help in the past.

I have a spreadsheet that I want to find a statement like "section 1" that
could change the line it is on then backup two line and insert a line or
maybe 5 lines.

I have tried to record a macro but it keeps selecting the line and I
thought
there was an offset command in VB?

Columns("A:A").Select
Selection.Find(What:="Section 1", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("A8").Select
Selection.EntireRow.Insert






All times are GMT +1. The time now is 06:54 AM.

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