I have the following macro, with altered arrays for simplicity.
It works perfectly in filtering the data I need (in this example, it would keep the columns with Header A, B, or D.
However, I added a graphic to the top g my excel, causing my headers to be in a row different than row 1
How would I got about altering this macro for it to function as it did, with the column headers in a different row placement?
Thank You!
Public Sub Macro1()
Dim iLastCol As Long
Dim iPtr As Long
Dim MyHeaders As Variant, xMatch As Variant
MyHeaders = Array("A", "B", "D")
iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
For iPtr = iLastCol To 1 Step -1
xMatch = Application.Match(Cells(1, iPtr).Value, MyHeaders, 0)
If IsError(xMatch) Then
Columns(iPtr).Delete Shift:=xlToLeft
End If
Next iPtr
[TABLE="class: grid, width: 350"]
<TBODY>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]4[/TD]
[TD]4[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]5[/TD]
[/TR]
</TBODY>[/TABLE]
It works perfectly in filtering the data I need (in this example, it would keep the columns with Header A, B, or D.
However, I added a graphic to the top g my excel, causing my headers to be in a row different than row 1
How would I got about altering this macro for it to function as it did, with the column headers in a different row placement?
Thank You!
Public Sub Macro1()
Dim iLastCol As Long
Dim iPtr As Long
Dim MyHeaders As Variant, xMatch As Variant
MyHeaders = Array("A", "B", "D")
iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
For iPtr = iLastCol To 1 Step -1
xMatch = Application.Match(Cells(1, iPtr).Value, MyHeaders, 0)
If IsError(xMatch) Then
Columns(iPtr).Delete Shift:=xlToLeft
End If
Next iPtr
[TABLE="class: grid, width: 350"]
<TBODY>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]4[/TD]
[TD]4[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]5[/TD]
[/TR]
</TBODY>[/TABLE]