Macro to delete Column

K

Kim

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
 
J

Jacob Skaria

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
 

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