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

  • Thread starter Thread starter luis
  • Start date Start date
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
 
You will benefit from using the vbe HELP index for insert, delete, etc.
Also, using the macro recorder should benefit.
 
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
 
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
 
Back
Top