insert a line via macro

D

Don

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
 
R

Roger Govier

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
 
G

Gord Dibben

If you use the Relative References button when recording you should get the
Offset code.


Gord Dibben MS Excel MVP
 

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

Top