ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to delete Column (https://www.excelbanter.com/excel-discussion-misc-queries/243239-macro-delete-column.html)

Kim

Macro to delete Column
 
Hi all,

I tried to record a macro to delete some column. Here is what I got but when
I run the macro it didn't performe correctly:

Sub Selection()

Sheets("Negotiation Tool Report").Select
Sheets("Negotiation Tool Report").Copy After:=Sheets(1)
Sheets("Negotiation Tool Report (2)").Select
Sheets("Negotiation Tool Report (2)").Name = "Selection"
Columns("A:A").Select
ActiveCell.Delete Shift:=xlToLeft
Columns("M:Z").Select
Selection.Delete Shift:=xlToLeft
Sheets.Add After:=Sheets(Sheets.Count)

When I run it keep come out as error on Selection.Delete. I've tried
changing Selection to ActiveCell but the result is that it select the cell
but didn't delete them.

Can anyone help?

Thanks.
Kim

Jacob Skaria

Macro to delete Column
 
Try the below

Dim ws As Worksheet
Set ws = Sheets("Negotiation Tool Report")

ws.Copy After:=Sheets(1)
Set ws = ActiveSheet
ws.Name = "Selection"

ws.Columns("A").Delete
ws.Columns("M:Z").Delete
Sheets.Add After:=Sheets(Sheets.Count)

If this post helps click Yes
---------------
Jacob Skaria


"Kim" wrote:

Hi all,

I tried to record a macro to delete some column. Here is what I got but when
I run the macro it didn't performe correctly:

Sub Selection()

Sheets("Negotiation Tool Report").Select
Sheets("Negotiation Tool Report").Copy After:=Sheets(1)
Sheets("Negotiation Tool Report (2)").Select
Sheets("Negotiation Tool Report (2)").Name = "Selection"
Columns("A:A").Select
ActiveCell.Delete Shift:=xlToLeft
Columns("M:Z").Select
Selection.Delete Shift:=xlToLeft
Sheets.Add After:=Sheets(Sheets.Count)

When I run it keep come out as error on Selection.Delete. I've tried
changing Selection to ActiveCell but the result is that it select the cell
but didn't delete them.

Can anyone help?

Thanks.
Kim



All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com