how to insert columns and rows? how to delete a worksheet?

L

luis

sorry if this is obvious....but I am trying to get a handle on excel
basic... (and my background is C++....)

In a sub, how can I insert a column in a worksheet? or a row?

and how can I delete a worksheet?... it works when it exists, but sometimes
I don't know if the named sheet exists in the workbook... so is there a way
to text if it exists before trying to delete (I get an error...)... e.g.
something like
if Worksheets("someName").Exists=true then
Worksheets("someName").delete
enf if


Many THANKS!!!

luis
 
D

Don Guillett

You will benefit from using the vbe HELP index for insert, delete, etc.
Also, using the macro recorder should benefit.
 
C

Chip Pearson

Luis,

To insert a row, use the following. The row will be inserted
above the specified row:

Rows(3).Insert

To insert a column, use the following. The column will be
inserted to the left of the specified column.

Columns("C").Insert

To delete a worksheet, use the following. The On Error Resume
Next will ignore the error raised if the sheet does not exist.

On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Sheet1").Delete
Application.DisplayAlerts = True
On Error GoTo 0


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
L

luis

Chip,

many thanks!

luis

PS: The "On Error Resume Next" was what I was looking for ! thanks!... I had
tried the other stuff. Many thanks
 

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