If statement for entire column rather than cell by cell...

jillian728

Active Member
Joined
Jun 20, 2003
Messages
250
I'm sure that there is a smarter way to do this... Does anyone have any suggestions on how to apply this code to the entire column rather than cell by cell?

Columns("Q:Q").Select
If Range("Q2").Value <> "" Then
If Range("Q2").Value <> "Offer Accepted" Then
Range("Q2").Select
Selection.ClearContents
End If
End If
If Range("Q3").Value <> "" Then
If Range("Q3").Value <> "Offer Accepted" Then
Range("Q3").Select
Selection.ClearContents
End If
End If
 
Re: If statement for entire column rather than cell by cell.

You're both great. Here is the code that I ended up with:


'**This code looks at column Q and deletes all cells that do not have the word Accepted in it.**'

For Each cell In Range("Q2:Q" & Range("Q65536").End(xlUp).Row)
If cell <> "" And Not cell Like "*Accepted*" Then cell.ClearContents
Next cell
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Re: If statement for entire column rather than cell by cell.

You're both great. Here is the code that I ended up with:


'**This code looks at column Q and deletes all cells that do not have the word Accepted in it.**'

For Each cell In Range("Q2:Q" & Range("Q65536").End(xlUp).Row)
If cell <> "" And Not cell Like "*Accepted*" Then cell.ClearContents
Next cell
 
Upvote 0
Re: If statement for entire column rather than cell by cell.

Good job Jillian -- finally got it working -- now let us keep EXCELing!
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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