Column Delete based on String
I think this should do what you want:
Sub Test()
Dim rngToTest As Range
Dim rngCell As Range
If IsEmpty(Cells(256)) Then
Set rngToTest = Range(Cells(1), Cells(256).End(xlToLeft))
Else
Set rngToTest = Rows(1).Cells
End If
Application.ScreenUpdating = False
For Each rngCell In rngToTest
If rngCell.Value = "TESTING" Then
rngCell.EntireColumn.Delete
End If
Next
Application.ScreenUpdating = True
End Sub
RBS
"scott" wrote in message
...
1. I only set the color of the cell for testing purposes. My code dies on
Delete line.
2. I don't need to sort, I need to ...
3. Set the range to test from A1 to last non-blank cell on Row 1
4. Find any cell with value of "TESTING" and if so, delete that column
Please help me with these steps, I've wasted 2 weekends now just trying to
get some basic moving around the sheet actions.
"Bob Phillips" wrote in message
...
Scott,
To sort the code you need
Sub testSelectDelete()
Dim cell As Range
For Each cell In Selection
If Not IsEmpty(cell) And cell.Value = "TESTING" Then
cell.Interior.Color = RGB(255, 255, 192)
cell.EntireColumn.Delete
End If
Next
End Sub
But why do you test for not empty and has a value of "TESTING" (the
second
can only mean tat it isn't empty), and why do you set the cell's colour,
then delete the whole column (thereby deleting the cell you have just
set)?
--
HTH
Bob Phillips
"scott" wrote in message
...
I'm desperately tring to delete a column if a cell within a range equals
"TESTING". Below gives error "Method 'Range' of Object '_Global'
failed".
I
also need this selection to auto set to A1 to last non-blank cell on row
1.
The cell coloring line works and is just there so I know I'm on the
right
cell.
Any help in fixing these 2 actions may save a lot of gray hair.
Sub testSelectDelete()
Dim cell As Range
For Each cell In Selection
If Not IsEmpty(cell) And cell.Value = "TESTING" Then
cell.Interior.Color = RGB(255, 255, 192)
Range(cell).EntireColumn.Delete
End If
Next
End Sub
|