Delete columns

  • Thread starter Thread starter Elsie
  • Start date Start date
E

Elsie

Hi, I am trying to get my macro to delete a particular column when the first
row of that column contains a certain keyword, however I am only able to
delete the first row of that column. In addition, how come " Workbooks.Open
Filename:=fi" keeps giving me error 1004 - runtime error that says it can't
find the file?

Sub redundantCols()

Dim fi As String, sh As String
Dim c As String
Dim i As Integer, j As Integer, k As Integer
fi = InputBox("Enter the name of file", "Source file")
sh = InputBox("Enter the name of the sheet", "Source sheet")
fi = fi & ".xls"

Workbooks.Open Filename:=fi
Windows(fi).Activate
Sheets(sh).Select

With Workbooks(fi).Worksheets(sh)
.Cells(1, 9) = "Item Description"
i = 1
For j = 1 To 16
c = Cells(i, j)

If c = "Description" Or c = "Item" Then
.Cells(i, j) = ""
End If

Next j

End With

End Sub
 
Back
Top