Macro to copy sheet, then delete one column

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
I recorded a macro to copy a sheet and delete column B.
When I execute the macro, it copy the sheet and deletes column B but it ALSO eliminates column A. Not good
Here is the code that I use, help is appreciated
--------------------
Sub Copy1()

' copy sheet
Windows("price_Autocad-May-06-02.xls").Activate
Sheets(" US ASC").Select
Sheets(" US ASC").Copy Before:=Workbooks("price_S.xls").Sheets(2)
' delete column B
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
End Sub
-----------------
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
G'day

Columns("B:B").Select
Selection.Delete Shift:=xlToLeft

That piece of code seems to work on my machine ok. Is there any more code you left out that might get involved? A Loop perhaps?

Adam
 
Upvote 0
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=Sheets(1)
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("B1").Select

edit as needed
 
Upvote 0
To Asala42:

I actually did NOT delete any code, but added some comments.

If I delete C or D all is well, but the minute I remove B it also removes A
 
Upvote 0
Hmm...funky

I was able to create a couple test files to test your code - seems ok here. column A stays intact.

Do you by any chance have a merged cell in those columns? Anything weird in either Column A or B in your current spreadsheet.

For the hell of it, see if you can make the code work on a couple test files.

Sorry I can't be more of a help,
Adam
 
Upvote 0
No need to select or shift to left (it inherantly does so). Try:

Code:
Sub Copy1()
' copy sheet
Sheets(" US ASC").Copy Before:=Workbooks("price_S.xls").Sheets(2)
' delete column B
[B:B].Delete
End Sub

If this code deletes column A, it's time to right click on the sheet in question, click view code and see what's happening there (or in the 'thisworkbook' module).

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
wave.gif

This message was edited by NateO on 2002-05-06 14:08
 
Upvote 0
these niothing in my code ok you must change the sheet names but ok did A delete as well?


If so i would say we have alians and need to look at that book, anyother codes...

something wrong

suggest make col b into object say
[B:B].Delete

so try :

sub JACK()
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=Sheets(1)
[B:B].Delete

end sub
 
Upvote 0

Forum statistics

Threads
1,213,511
Messages
6,114,054
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top