Delete entire column based on column heading (named range?)

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
163
Hello,

I receive daily data that contains over 100 columns, most of which I don't need. But the issue is that the columns in this data are usually in different order and I only really need about 15 of the columns.

What I would like to do is have a macro that copies only the 15 columns that I need (based on specific column headings), and paste only these columns to another sheet.

I thought about using a named range to specify which column headings I want to use but I'm not sure if this would work or if there is an easier solution?

The column headings I receive will always be the same, just in different order.

Thanks in advance for your help.
 

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.
Could you just create a pivot table? And change the range daily?

Hi @mrshl9898
Sorry, I'm not really sure what you mean. Do you mean create a pivot table by manually selecting the 15 columns i need?
Because I have to do this function daily, I'm just looking for an automated way to exclude unnecessary columns, which gives me a much cleaner page to do the other analysis required.
Can the pivot table from a named range be put into a macro?
 
Upvote 0
Original Data

MOCK_DATA.xlsx
ABCDEF
1idfirst_namelast_nameemailgenderip_address
21BlondyAnfonsibanfonsi0@nifty.comFemale78.193.170.245
32DanitSkittrelldskittrell1@example.comFemale197.197.74.69
43LelaDuffreelduffree2@tripadvisor.comFemale48.12.107.187
54LoralieLinzeellinzee3@goodreads.comFemale99.147.116.191
65MyrtleLandemlande4@desdev.cnFemale254.193.153.190
76GoldaClegggclegg5@pen.ioFemale99.247.144.41
87WinnySchuhwschuh6@goo.glFemale140.191.80.52
98DarrickSonesdsones7@is.gdMale199.22.141.227
109RickiCarvillarcarvilla8@psu.eduMale194.92.59.175
1110FelitaJanesfjanes9@bbb.orgFemale51.100.64.123
1211AloisiaGeddesageddesa@gnu.orgFemale84.160.26.241
1312DonMaundrelldmaundrellb@t.coMale120.225.55.217
1413WangTorrejonwtorrejonc@phpbb.comMale227.139.35.216
1514MuffinHaycockmhaycockd@washington.eduFemale131.41.210.179
1615ReadeBiffinrbiffine@edublogs.orgMale79.187.197.114
data


MOCK_DATA.xlsx
ABC
1first_namelast_nameemail
2BlondyAnfonsibanfonsi0@nifty.com
3DanitSkittrelldskittrell1@example.com
4LelaDuffreelduffree2@tripadvisor.com
5LoralieLinzeellinzee3@goodreads.com
6MyrtleLandemlande4@desdev.cn
7GoldaClegggclegg5@pen.io
8WinnySchuhwschuh6@goo.gl
9DarrickSonesdsones7@is.gd
10RickiCarvillarcarvilla8@psu.edu
11FelitaJanesfjanes9@bbb.org
12AloisiaGeddesageddesa@gnu.org
13DonMaundrelldmaundrellb@t.co
14WangTorrejonwtorrejonc@phpbb.com
15MuffinHaycockmhaycockd@washington.edu
16ReadeBiffinrbiffine@edublogs.org
Sheet1


With Power Query here is the Mcode in which you select the columns you wish to keep.

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"first_name", type text}, {"last_name", type text}, {"email", type text}, {"gender", type text}, {"ip_address", type text}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"first_name", "last_name", "email"})
in
    #"Removed Other Columns"

So long as the headers don't change names, this will work for you
 
Upvote 0
Hi @mrshl9898
Sorry, I'm not really sure what you mean. Do you mean create a pivot table by manually selecting the 15 columns i need?
Because I have to do this function daily, I'm just looking for an automated way to exclude unnecessary columns, which gives me a much cleaner page to do the other analysis required.
Can the pivot table from a named range be put into a macro?

Just meant select all columns needed in the Pivot, once the Pivot is set up you won't need to change anything but the source. Or the above post.
 
Upvote 0
Thank you. I'm not that familiar with Power Query, but I'll look into your suggestions.
 
Upvote 0

Forum statistics

Threads
1,215,005
Messages
6,122,661
Members
449,091
Latest member
peppernaut

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