Hello All,
I was wondering how could I delete all the columns I do not need from a report without having to either mention them or have their address?
Usually when I want to clean up a report I delete columns using something like:
Or something like this
Or
But I noticed using any of this methods leaves me with a gap, what happens if the order of the columns change and no longer can use a range, what if they add another column or columns????? None of this will delete the new ones.
So I was wondering how would I go about deleting all the columns except those Whose headers I want to keep i.e
go from
Excel 2012
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]Don’t want[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]Don’t want[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]Don’t want[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 3[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
</tbody>
To
Excel 2012
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 3[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
</tbody>
[TABLE="width: 85%"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I was wondering how could I delete all the columns I do not need from a report without having to either mention them or have their address?
Usually when I want to clean up a report I delete columns using something like:
Code:
Range("B:B,D:D,F:G,I:I,K:K,M:N,P:S,U:BH,BJ:BJ,BL:BX").Delete Shift:=xlToLeft
Or something like this
Code:
For iCntr = lCol To 1 Step -1 If Cells(1,iCntr) = "Whatever" Then
Columns(iCntr).Delete
End If
Next
Or
Code:
For iCntr = lCol To 1 Step -1 Select Case Cells(1, lCol)
Case "Header1", "Header2", "", "Unnamed Header"
Columns(iCntr).Delete
End Select
Next
But I noticed using any of this methods leaves me with a gap, what happens if the order of the columns change and no longer can use a range, what if they add another column or columns????? None of this will delete the new ones.
So I was wondering how would I go about deleting all the columns except those Whose headers I want to keep i.e
go from
Excel 2012
A | B | C | D | E | F | G | H | I | J | |
---|---|---|---|---|---|---|---|---|---|---|
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]Don’t want[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]Don’t want[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]Don’t want[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 3[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
</tbody>
Hoja1
To
Excel 2012
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep 3[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F4B084]#F4B084[/URL] , align: center"]I want to keep[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
[TD="align: center"]Data[/TD]
</tbody>
Hoja1
[TABLE="width: 85%"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Last edited: