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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,215,472
Messages
6,125,011
Members
449,204
Latest member
tungnmqn90

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