PDA

View Full Version : Solved: Delete Column that do not have headers "XYZ"



mduff
03-31-2013, 07:46 PM
I have a sheet that over 60 Column's each one has a header then data.
I only need to keep the data that has the following headers in row 1:

WeekNum
ROUTING_SET
Date
lookup
Day
Interval
HOUR MINUTE
A SCH ADJ
RF AHT
RF NCO
Everything else can be deleted, does any one have any VBA code that can help with this task?

thanks

Teeroy
03-31-2013, 11:53 PM
Try on a copy first. It will affect only the Activesheet.

Sub deleteColumnsNotRequired()
Dim Reqd, rng As Range
Reqd = Array("WeekNum", "ROUTING_SET", "Date", "Lookup", "Day", "Interval", "Hour Minute", _
"A SCH ADJ", "RF AHT", "RF NCO")
For Each rng In Range("A1:" & Cells(1, Columns.Count).End(xlToLeft).Address)
If IsError(Application.Match(rng.Value, Reqd, 0)) Then
rng.EntireColumn.Delete
End If
Next
End Sub

snb
04-01-2013, 01:09 AM
sub M_snb()
c00="|WeekNum|ROUTING_SET|Date|lookup|Day|Interval|HOUR MINUTE|A SCH ADJ|RF AHT|RF NCO|"

for each cl in rows(1).specialcells(2)
if instr(c00,"|" & cl.value & "|")=0 then cl.value=""
next

rows(1).specialcells(4).entirecolumn.delete
end sub

mduff
05-10-2013, 08:27 AM
Both worked thanks a lot