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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Code:
    For x = 2 to range("Q65536").End(xlup).Row
        If Range("Q" & x).Value <> "" and Range("Q" & x).Value <> "Offer Accepted" Then Range("Q" & x).ClearContents
    Next x
 
Upvote 0
Re: If statement for entire column rather than cell by cell.

Thanks Jacob.

This worked perfectly. This is something that I will be able to use over and over again.
 
Upvote 0
Re: If statement for entire column rather than cell by cell.

Hi Jillian:

In addition to Jacob's, you may also try ...
Code:
For Each cell In Range("Q2:Q" & Range("Q65536").End(xlUp).Row)
        If cell <> "" And cell = "Offer Accepted" Then cell.ClearContents
    Next cell
 
Upvote 0
Re: If statement for entire column rather than cell by cell.

Thanks for the additional method Yogi. I'll try that out too.

Quick question - I know that <> is used in formulas for does not equal. What would I put in place of <> to represent "does not contain". I'm not sure if there is an option for this.

Thanks!
 
Upvote 0
You mean if it has part of the value? You can try

If range("A1").Value not like ("ab*")

use * for the wildcard
 
Upvote 0
Re: If statement for entire column rather than cell by cell.

Hi Jacob:

I think it should be ...

If not Range("A1").value like ("ab*") ....

What do you think?
 
Upvote 0
Yeah your right. That's what I get for not typing up the code in vbe. I tried mine in vbe and excel got pissed right away.

Thanks
 
Upvote 0
Re: If statement for entire column rather than cell by cell.

Let us make it even ...

If not Range("A1").value like ("*ab*") ...
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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