Hi There,
I have the below scenario.
Sheet 1 has four columns and following the values in the row .( Name , Address, ID, Company)
At times , Name column needs to be deleted; Some times , Address column needs to be deleted.
So, there should a second sheet2. In here , Column A1 can have Name, Column A2 can have Address.
Based on this list from Sheet2, Columns in Sheet1 should be deleted. Can someone suggest a macro for this ?
Thanks
Below is the code which i tried but Can someone suggest how to pass list from Sheet2 instead of following line in the code
ColAry = Array("Name", "Id")
I need a ColAry = Array ( I want to pass a range from Sheet2 A1:A2 )
-----------------------------------------------
Sub DeleteColumns()
Dim ColAry, i As Long, fc As Long
Application.ScreenUpdating = False
ColAry = Array("Name", "Id")
With Sheets("Sheet1")
For i = LBound(ColAry) To UBound(ColAry)
fc = 0
On Error Resume Next
fc = Application.Match(ColAry(i), .Rows(1), 0)
On Error GoTo 0
If fc > 0 Then
.Columns(fc).Delete
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
Bookmarks