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

jillian728

Board Regular
Joined
Jun 20, 2003
Messages
243
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
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853
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
 

jillian728

Board Regular
Joined
Jun 20, 2003
Messages
243
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.
 

Yogi Anand

MrExcel MVP
Joined
Mar 12, 2002
Messages
11,454
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
 

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853

ADVERTISEMENT

Glad to help

Take Care
 

jillian728

Board Regular
Joined
Jun 20, 2003
Messages
243
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!
 

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853

ADVERTISEMENT

You mean if it has part of the value? You can try

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

use * for the wildcard
 

Yogi Anand

MrExcel MVP
Joined
Mar 12, 2002
Messages
11,454
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?
 

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853
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
 

Yogi Anand

MrExcel MVP
Joined
Mar 12, 2002
Messages
11,454
Re: If statement for entire column rather than cell by cell.

Let us make it even ...

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

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,653
Members
414,083
Latest member
Mrsash

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
Top