Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Delete columns

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Delete columns

How about:

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


"iperlovsky" wrote:

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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 342
Default Delete columns

Sub Macro1()

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

End Sub


"iperlovsky" wrote:

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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Delete columns

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.
--
Cheers,
Ryan


"iperlovsky" wrote:

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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Delete columns

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.

"iperlovsky" wrote:

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?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Delete columns

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.
--
Cheers,
Ryan


"JLGWhiz" wrote:

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.

"iperlovsky" wrote:

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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
delete columns if 0 jatman New Users to Excel 2 January 3rd 09 04:39 AM
create a macro to delete columns and then border remaining columns Jane777 Excel Programming 1 July 18th 07 12:08 AM
Delete all Columns with a certain value [email protected] Excel Programming 3 May 17th 07 02:41 AM
Delete columns Mike D. Excel Programming 3 May 5th 07 10:24 PM
merge text from 2 columns into 1 then delete the old 2 columns sleepindogg Excel Worksheet Functions 4 March 30th 06 07:25 PM


All times are GMT +1. The time now is 04:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"