R
Robert H
Im trying to loop through each cell in the first row of a sheet and if
the cell contains the text "ID" the delete that entire column. the
following code works well except it starts at the 11th column instead
of at the first also the curCell value is blank after a certain number
of cells even tho there is still data in the location it is looking
at.
Sub DeleteIDCol()
'removes the LC_ID and QD_ID columns.
Dim colHead As Range
Dim n As Integer
Dim curCell As Range
Set colHead = Rows(1)
For n = 1 To colHead.Columns.Count
Set curCell = Cells(1 & n)
If InStr(1, curCell, "ID") > 0 Then
curCell.EntireColumn.Delete
End If
Next n
End Sub
the cell contains the text "ID" the delete that entire column. the
following code works well except it starts at the 11th column instead
of at the first also the curCell value is blank after a certain number
of cells even tho there is still data in the location it is looking
at.
Sub DeleteIDCol()
'removes the LC_ID and QD_ID columns.
Dim colHead As Range
Dim n As Integer
Dim curCell As Range
Set colHead = Rows(1)
For n = 1 To colHead.Columns.Count
Set curCell = Cells(1 & n)
If InStr(1, curCell, "ID") > 0 Then
curCell.EntireColumn.Delete
End If
Next n
End Sub