Find cells in a range matching cells in another range and clear contents VBA

danno79

New Member
Joined
Oct 28, 2009
Messages
45
Hi the follwing piece of code finds the left three chars of cell h116 in rng m44:m75 and clears contents of the cell. I would like to modify it so that it checks for a range of different characters i.e in H116:H147 (what i thought was the obvious did not work);-

Rich (BB code):
With ActiveSheet
    For Each cell In .Range("M44:M75")
        If Left(cell.Value, 3) = .Range("H116:147").Value Then
            cell.ClearContents
            cell.Interior.ColorIndex = xlNone
        End If
    Next
End With

Thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this, it uses x to step through the cells in the range H116 to H147

Code:
With ActiveSheet
Dim x As Integer

For x = 116 To 147
        For Each cell In .Range("M44:M75")
            If Left(cell.Value, 3) = .Range("H" & x).Value Then
                cell.ClearContents
                cell.Interior.ColorIndex = xlNone
            End If
        Next cell
Next x
    End With
 
Upvote 0
Thanks Stuart - this is just what iw as after. Iknew there would be a fairly simple way to do it - as you might have guessed i'm still learning....
 
Upvote 0
That's OK, I'm still learning to - Mr Excel is a fantastic resource for help and I have found many solutions by searching this site.
 
Upvote 0

Forum statistics

Threads
1,222,830
Messages
6,168,507
Members
452,194
Latest member
Lowie27

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top