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 Mar 18th, 2002, 07:51 AM   #1
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default

I have a file with name, address city state zip. What I would like to do is have a macro that keeps certain states in the list but removes all others and if possible put those bad states on a seperate worksheet??

Now, I'm not that great at code but if it has to be, I think I need to know how to put the code in. Any help would be appreciated.

jbyrne is offline   Reply With Quote
Old Mar 18th, 2002, 08:01 AM   #2
Mudface
MrExcel MVP
 
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
Default

Not quite with you, what criteria would you use to determine whether or not a state is bad? (Apart from Utah, of course).
Mudface is offline   Reply With Quote
Old Mar 18th, 2002, 08:07 AM   #3
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default

In my line of work, we can't deal with certain states. So what I want to do is have the ability to keep certain states and remove and place on another worksheet, all others.

Hope that's clear. Thanks for replying
jbyrne is offline   Reply With Quote
Old Mar 18th, 2002, 08:38 AM   #4
Mudface
MrExcel MVP
 
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
Default

I can see how it might be done, but it might be pretty tricky to say the least, especially not knowing precisely what you want. I'm on my day off though and at a loose end, so if you'd like to send me a sample worksheet, along with details of what states you want excluding etc. I could get back to you within an hour or two, if you like.



[ This Message was edited by: Mudface on 2002-03-18 14:34 ]
Mudface is offline   Reply With Quote
Old Mar 18th, 2002, 08:58 AM   #5
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default

Thanks, I'll prepare a sample list and email it to you. Thanks!
jbyrne is offline   Reply With Quote
Old Mar 18th, 2002, 03:22 PM   #6
Mudface
MrExcel MVP
 
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
Default

Wasn't that difficult, but getting the file back to has been a nightmare (bloody AOL ). In case you don't get it, the E-Mail I sent was as follows: -

The following works for a couple of your requirements, but finding whether an entry is or is not a state is beyond me. The best I can suggest for that is to type in the names/ abbreviations of all the states, define a name for them, click on the column with your state entries and select Data-Validation, choose List and in the source box, put =States. With the column still selected, click on Tools-auditing-Show Toolbar (if necessary) and click on circle invalid data, then copy, paste and delete the rows by hand. You can leave the validation intact so that future entries can't be anything but a state.

The modifications I've made to your original sheet were as follows: -

1. Inserted a new worksheet and typed in the names of the states you want filtered out and named the range of those states MyStates. Also given your data column headings (important).
2. Inserted a command button on sheet1 and named it Extract. Click on this or press Alt-C to run the macro.
3. Opened up the VBA editor and inserted a new module and a new procedure called ExtractStates.

The code transfers filtered data from Sheet1 to Sheet2 based on the criteria in the MyStates range on Sheet4. You'll need to change the code accordingly if you can't fit this in with your current workbook.

Hope it works alright for you, it would have been with you quicker but Aol sucks big time ,

Regards

Chris


The code in the sub is: -

Public Sub ExtractStates()

Application.ScreenUpdating = False
Sheet1.Rows(1).Copy Destination:=Sheet2.Range("A1")
Sheet1.UsedRange.AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=Sheet4.Range("MyStates")
On Error Resume Next
Sheet1.UsedRange.CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Sheet2.Range("A65536").End(xlUp).Offset(1, 0)

Sheet1.Cells(1, 1).CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0

With Sheet1.Range("a1")
.AutoFilter field:=4, Criteria1:="="
.CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Sheet2.Range("A65536").End(xlUp).Offset(1, 0)
.CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
Sheet1.AutoFilterMode = False
Sheet2.UsedRange.Columns.AutoFit
Application.ScreenUpdating = True

End Sub
Mudface 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 11:03 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