Delete columns

  • Thread starter Thread starter iperlovsky
  • Start date Start date
I

iperlovsky

Would someone be able to provide guidance on how to write a routine to delete
columns A through AS in Sheet 1 only in a 3-Sheet workbook?
 
How about:

ActiveWorkbook.Worksheets("Sheet1").Select
ActiveSheet.Columns("A:AS").Select
Selection.Delete Shift:=xlToLeft
 
Sub Macro1()

ThisWorkbook.Worksheets("Sheet1").Columns("A:AS").Delete shift:=xlToLeft

End Sub
 
Actually the previous two responses, by egun and TomPl do not test the
workbook to see if there are 3 Sheets in the workbook. Here is what you will
need to test the number of sheets in the workbook then execute the Column
Delete.

Option Explicit

Sub DeleteSheets()

If Sheets.count = 3 Then
ThisWorkbook.Worksheets("Sheet1").Columns("A:AS").Delete
End If

End Sub

Hope this helps! If so please click "Yes" below.
 
In case the first sheet is not named "Sheet1":

Sub delCol()
Sheets(1).Columns("A:AS").Delete
End Sub

There is no need to test for the number of sheets since you only want to
execute on sheet one. The Shift:=xlToLeft is the default so that is
unnecessary in this case. You would need the Shift parameter if you want to
shift right. Using the Sheet index number 1 picks the first sheet tab on the
left as it appears in the window view, so if that is not the Sheet1 you want
then you would have to specify the sheet name or its index number. This
might be more than you wanted to know.
 
His question stated he only wanted to delete the columns in a 3 sheet
workbook. That is why he needs to test for the number of sheets in the
workbook.
 

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

Back
Top