MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 25th, 2002, 04:21 PM   #1
khickey
New Member
 
Join Date: Apr 2002
Posts: 16
Default

I need to clear all cells in a column that have a particular value. The value is sometimes a constant like "0" (zero) and sometimes is a value based on a formula. Is there a VBA code that will allow me to select those cells in column matching a particular value and clear them?

Cheers
khickey is offline   Reply With Quote
Old Apr 25th, 2002, 04:23 PM   #2
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

why use vba find and replace


__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old Apr 25th, 2002, 04:30 PM   #3
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

This should work on formulae results or values:

Code:
Sub deltime()
For Each Cell In [a:a]
If Cell.Value = "0" Then Cell.ClearContents 'put any value you want here
Next Cell
End Sub
Change [a:a] to the appropriate column. Hope this helps.

_________________
Cheers, NateO
"Me no are no nice guy."

[ This Message was edited by: NateO on 2002-04-25 15:49 ]
NateO is offline   Reply With Quote
Old Apr 25th, 2002, 04:47 PM   #4
khickey
New Member
 
Join Date: Apr 2002
Posts: 16
Default

Thanks guys, that worked fine
khickey is offline   Reply With Quote
Old Sep 29th, 2009, 09:03 AM   #5
Bench
Board Regular
 
Join Date: Aug 2009
Posts: 116
Default Re: clear cells using VBA

This looks really helpful, when i try is though i get
Run Time Error 13:

"Type Mismatch"

and the below is highlighted

If Cell.Value = "00/01/1900" Then

I have tried changing the month and day around and also tried changing it to "ben" and the same error occurs.

Secondly, will this work on a VLOOKUP result, which 00/01/1900 is

Thanks

Ben

PS. I've tried this on some other columns and managed to get it mostly working, it seems the VLOOKUP result is scuppering things, any suggestions?

Last edited by Bench; Sep 29th, 2009 at 09:06 AM. Reason: Additional info
Bench is offline   Reply With Quote
Old Sep 29th, 2009, 09:12 AM   #6
BC...
Board Regular
 
Join Date: Sep 2005
Posts: 135
Default Re: clear cells using VBA

that code won't work for a vlookup result. to do that you need to copy the vlookup result and paste it as a value. so if column A is your vlookup column, I'd copy and paste column A onto itself as values and then do a find/replace for specific values.
BC... is offline   Reply With Quote
Old Sep 29th, 2009, 09:12 AM   #7
rorya
MrExcel MVP
Moderator
They call me "Mary"
 
rorya's Avatar
 
Join Date: May 2008
Location: In the flat field
Posts: 16,243
Default Re: clear cells using VBA

Do you have any error values in your data? You will get a Type Mismatch error if you try and compare error values like that.
__________________
Rory
Microsoft MVP - Excel.

My wife treats me like a god - she ignores my existence until she wants something.
rorya is online now   Reply With Quote
Old Sep 29th, 2009, 12:13 PM   #8
Bench
Board Regular
 
Join Date: Aug 2009
Posts: 116
Default Re: clear cells using VBA

Thanks i've tried that but still no luck, even changed from date to general, i think it may be as Rorya says, "00/01/1900" is the result i'm trying to lose, this i guess is an error as it is saying that the data in the other spreadsheet is blank.

Is there a way around this, a way to blank out the errors? and not simply changing the font to white

I'm wondering also if it may be the way date is formatted within the VBA, should it be done dd/mm/yyyy or is there another format required?

Last edited by Bench; Sep 29th, 2009 at 12:15 PM. Reason: additional info
Bench is offline   Reply With Quote
Old Sep 29th, 2009, 12:15 PM   #9
rorya
MrExcel MVP
Moderator
They call me "Mary"
 
rorya's Avatar
 
Join Date: May 2008
Location: In the flat field
Posts: 16,243
Default Re: clear cells using VBA

00/01/1900 is not an error. If the VLOOKUP were returning an error, you would see #N/A in the cell. You could try using:
Code:
If Cell.Value2 = 0 then
__________________
Rory
Microsoft MVP - Excel.

My wife treats me like a god - she ignores my existence until she wants something.
rorya is online now   Reply With Quote
Old Sep 29th, 2009, 01:29 PM   #10
BC...
Board Regular
 
Join Date: Sep 2005
Posts: 135
Default Re: clear cells using VBA

You could add IF logic to your VLOOKUP to evaluate if it returns #N/A or #VALUE! using the ISERROR function. It will require you to have the VLOOKUP in the cell formula more than once, so on large spreadsheets it might be a concern since the VLOOKUP is a volatile function.
BC... is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes