View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Howard31 Howard31 is offline
external usenet poster
 
Posts: 100
Default Delete Specific Contents

Try this one it gives you the control of choosing which column to search and
which values:

Sub ClearSpecifiedValue()
Dim Sht As Worksheet, Rng As Range, LastRow As Long
Dim Str As String, Col As Variant
Dim i As Long

Col = InputBox("Enter the column you want to search")
If Col = "" Then Exit Sub

On Error Resume Next
Set Rng = Cells(1, Col)

Do Until Err.Number = 0
Err.Clear
Set Rng = Cells(1, Col)
If Err < 0 Then
MsgBox "Enter a valid Column in text format i.e. A, B..."
Col = InputBox("Enter the column you want to search")
Else
Exit Do
End If
Loop

'Get last row in specified column
Set Sht = ActiveSheet
With Sht
If .Cells(.Rows.Count, Col) < "" And .Cells(.Rows.Count) < 0 Then
LastRow = .Rows.Count
Else
LastRow = .Cells(.Rows.Count, Col).End(xlUp).Row
End If

Str = InputBox("Which value would you like to to delete?")
If Str = "" Then Exit Sub

For i = 1 To LastRow
If .Cells(i, Col) = Str Then .Cells(i, Col).ClearContents
Next i
End With
End Sub

The above code is case sensitive, if you want it to be not case sensitive
change the last If statement with the following:

If UCase(.Cells(i, Col)) = UCase(Str) Then .Cells(i, Col).ClearContents

Hope this helps
--
A. Ch. Eirinberg


"TGalin" wrote:

I would like to create a macro that will search Column A and every time it
finds a cell that says "User" or "Theodore Galin" the contents of that cell
will be deleted. Can you help me with this?