View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Column Delete based on String

I thought you said it was working?

Sub testSelectDelete()
Dim cell As Range
' selection.EntireRow.Hidden = False
For Each cell In Selection
If Not IsEmpty(cell) And cell.Value = "TESTING" Then
cell.EntireColumn.Hidden = True
End If
Next

End Sub

Coloring is gone. If you want to undo paste hiding, uncomment the
' selection.EntireRow.Hidden = False

--
Regards,
Tom Ogilvy



"Cattle Annie" wrote in message
...
Hi Tom
It doesn't like the last line Range etc.
Also I don't need the colouring bit, can this line be deleted?
Thanks Annie

"Tom Ogilvy" wrote:

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.Hidden = True
End If
Next

End Sub

--
Regards,
Tom Ogilvy

"Cattle Annie" wrote in message
...
Hi
Found this thread very interestiing. Am complete novice at

programming,
have tried this coding and it works for me, but I cannot then

re-instate
the
columns. Is it possible to HIDE the columns, which can be then be

un-hidden?

Thanks

"scott" wrote:

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