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>
</tbody>
To
Excel 2012
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
<tbody>
</tbody>
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 | |
---|---|---|---|---|---|---|---|---|---|---|
1 | I want to keep | I want to keep 1 | Don’t want | I want to keep | Don’t want | I want to keep 2 | I want to keep | Don’t want | I want to keep 3 | I want to keep |
2 | Data | Data | Data | Data | Data | Data | Data | Data | Data | Data |
3 | Data | Data | Data | Data | Data | Data | Data | Data | Data | Data |
4 | Data | Data | Data | Data | Data | Data | Data | Data | Data | Data |
5 | Data | Data | Data | Data | Data | Data | Data | Data | Data | Data |
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Hoja1
To
Excel 2012
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
1 | I want to keep | I want to keep 1 | I want to keep | I want to keep 2 | I want to keep | I want to keep 3 | I want to keep |
2 | Data | Data | Data | Data | Data | Data | Data |
3 | Data | Data | Data | Data | Data | Data | Data |
4 | Data | Data | Data | Data | Data | Data | Data |
5 | Data | Data | Data | Data | Data | Data | Data |
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Hoja1
<tbody>
</tbody>
Last edited: