Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert a new line using VB

Status
Not open for further replies.

ahau

Programmer
Apr 19, 2006
51
AU
Hi,

I was wondering if anyone might be able to help me here. How do i insert a new row in excel worksheets using VB?

For example, in the worksheets "Data", i have the following data as follows

A B C
1 Merchandise 500 300
2 02-000 300 400
3 Total 800 700
4 Grocery 1000 100
5 03-001 500 700
6 Total 1500 800

What I'd like to do is to be able to insert a newline after total, in this case, which is after row 3.

Here is my code that doesn't work.

If insertnewline = True Then
Worksheets("Data").Rows("3:3").Select
Worksheets.Selection.Insert Shift:=xlDown <--doesn't work
End If

Your help is greatly appreciated.

Thank you very much in advance
 
Hi
try

rows(4).entirerow.insert

Note, there is no need to select anything. If the sheet you are working on is active there is no need to reference it but you could reference it and the code will then work no matter which sheet is active!

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top