View Single Post
  #4   Report Post  
JE McGimpsey
 
Posts: n/a
Default

One way, with a few minor modifications:

Public Sub ClearColumnContents()
Dim rngToSearch As Range
Dim rngCurrent As Range
Dim strFirstAddress As String

With ActiveSheet
Set rngToSearch = .Range("B2:B" & _
.Range("B" & .Rows.Count).End(xlUp).Row)
End With
Set rngCurrent = rngToSearch.Find( _
What:="SD", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not rngCurrent Is Nothing Then
strFirstAddress = rngCurrent.Address
Do
rngCurrent.Offset(0, 2).ClearContents
Set rngCurrent = rngToSearch.FindNext(rngCurrent)
Loop Until rngCurrent.Address = strFirstAddress
End If
End Sub




In article ,
"StarBoy2000" wrote:

I've been looking around at other solutions and found the following that
works. But I can only get it to work on one row. I need it to loop thru
every row in column B, check for "SD" and clear the contents of the same row
in column D. Can you help me with that piece?

Public Sub ClearColumnContents()
Dim wks As Worksheet
Dim rngToSearch As Range
Dim rngFirst As Range
Dim rngCurrent As Range

Set wks = ActiveSheet
Set rngToSearch = wks.Range("B2")
Set rngCurrent = rngToSearch.Find("SD", , , xlWhole)
If Not rngCurrent Is Nothing Then
Set rngFirst = rngCurrent
Do
rngCurrent.Offset(0, 2).ClearContents

Set rngCurrent = rngToSearch.FindNext(rngCurrent)
Loop Until rngCurrent.Address = rngFirst.Address
End If
End Sub