Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to copy certain columns in excel

Status
Not open for further replies.

dburks1

Technical User
Apr 11, 2010
8
US
I have a worksheet that has almost 50 columns and the list is forever growing. For reporting reasons I only need to use some of the columns.

Does anyone know of a script that will allow me to indentify the columns that i want to keep and delete all of the other remaining columns?

For example keep "Column name 1", keep "column name 5" and and delete all other columns.

Thanks
 
You have to decide what columns to keep or delete based on your needs. Something you might find useful is to do what you need in a macro and then convert the logic. It is not always an exact “fit” but it can get you started. Open up a spreadsheet, click on record macro (use anyname you want), do what you want to do in the program, click stop recording, open up the macro and click on the visual basic edotor. Review the code. In the case of your post this is what was generated.

Code:
 Columns("B:D").Select
    Selection.Delete Shift:=xlToLeft
    Columns("C:G").Select
    Selection.Delete Shift:=xlToLeft[/code
 



Generally, I avoid DELETING and INSERTING columns/rows in Excel. There are hidden problems that can occur. Rather, HIDE, instead.

If you must delete column/rows, start at the right/bottom and work left/up. Otherwise you destroy your reference and will miss columns/rows and delete incorrect columns/rows.

BTW, if you are codeing within Excel, using VBA, please post VBA questions in forum707.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top