Your could try this code...
Sub Button1_Click()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim sourcesheet As Worksheet
Dim col As String
Dim colno As Long
Dim fullfilename As String
Dim filename As String
Set wb1 = ActiveWorkbook
fullfilename = Range("B1").Value & Range("B2").Value
filename = Range("B2").Value
On Error GoTo notfound
Workbooks.Open fullfilename
Set wb2 = ActiveWorkbook
Set sourcesheet = wb2.Worksheets("Sheet1")
On Error GoTo 0
For i = 1 To 9999
col = wb1.Worksheets("Sheet1").Range("D" & CStr(i)).Value
If col = "" Then
Exit For
End If
colno = wb1.Worksheets("Sheet1").Range("E" & CStr(i)).Value - (i - 1)
sourcesheet.Columns(colno).EntireColumn.Delete
Next i
Workbooks(filename).Close SaveChanges:=True
wb1.Activate
Exit Sub
notfound: MsgBox ("File not found")
End Sub
PS: Make sure you have a backup of your original file!!!
PPS: Assumes you enter your columns in ascending order in column D. Drag down formula in Column E to match column D.
Bookmarks