Clear Cell Based on Content of Another Cell

moheganburner

Board Regular
Joined
Dec 2, 2005
Messages
158
Hi guys. On "Sheet2", if a cell in Column F has the word "Ready" in it, I want to clear the contents of the corresponding cell in Column H. I'm picturing an if statement. I know this code doesn't do anything, but I didn't want to come to the board empty handed.



Code:
Sub ClearCell()
Dim Sheet2 As Long
Set Ws5 = Worksheets("Sheet2")
  
    With Ws5
        For x = 2 To Sheet2 'because I want to start searching in row 2

        Set foundRng = searchRng.Find(Ws5.Cells(x, 8))
            If foundRng Is Nothing Then
            Ws5.Range("H65536").ClearContents
            End If
        Next x
    End With
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Based on what you have, this will look in column F for the word "Ready" and clear the contents of column H
Code:
Sub ClearCell()
Dim Ws5 As Worksheet
Dim lRow as Long
Set Ws5 = Worksheets("Sheet2")
 
lRow = Ws5.Range("H65536").End(xlup).Row 'sets last row to last row of data with something in column H

    With Ws5
        For x = 2 To lastrow 'because I want to start searching in row 2
        If Cells(x,6) = "Ready" then cells(x,8).ClearContents
        Next x        
    End With
End Sub
 
Upvote 0
Awesome Gibbs, thanks! Just one mistake in your code... that "lastrow" should be "lRow" as previously defined.

MB
 
Upvote 0
Your welcome. Happy holidays. There are more potentially "slick" ways rather than going row by row....depending on if that meeted your exact needs or not.

Post back if problems,
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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