FuNeS13
Board Regular
- Joined
- Oct 25, 2016
- Messages
- 161
- Office Version
- 365
- 2016
- Platform
- Windows
- Mobile
- Web
I know I'm doing something wrong in this part of the code, but I don't know what...
what I want to do is if the titles on the first row exist in my array list, then I want to keep that column, if it doesn't exist then I want the column to be removed...
VBA Code:
Dim MyArray As Variant
Dim found As Boolean
Dim uB As Integer, lB As Integer
Dim LC As Long
MyArray = Array("Type", "Number", "Order", "Invoice Date", "Due/Paid Date", "Amount", "Shipment", "Customer", "Name", "Credit Limit", "Chk/Ref")
LC = Cells(1, Columns.Count).End(xlToLeft).Column '56 columns
uB = UBound(MyArray)
lB = LBound(MyArray)
c = 1
For i = lB To uB
Do Until c = LC + 1
If Range(Split(Cells(1, c).Address, "$")(1) & "1").Value = MyArray(i) Then
found = True
Else
found = False
End If
If found = False Then
Range(Split(Cells(1, c).Address, "$")(1) & ":" & Split(Cells(1, c).Address, "$")(1)).Select
Selection.Delete Shift:=xlToLeft
Else
GoTo nexti
End If
c = c + 1
Loop
nexti:
Next i
what I want to do is if the titles on the first row exist in my array list, then I want to keep that column, if it doesn't exist then I want the column to be removed...