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 29th, 2002, 09:53 AM   #1
dtaylor
Board Regular
 
Join Date: Mar 2002
Location: So Cal
Posts: 380
Default

Hello ALL,
I have a need for a macro that will open up all text files (with extension .csv) in a directory, find lines that have a cell entry of **** Header Line ****
and then delete those lines, close and save the files. There is only one column containing the string, col "J". The number of lines with a cell containing this string will vary as will the number of files.
There are 52 diff columns on each file and each are in the same format.

Any assistance would be gratefully recieved!

Thanks and have a great day....

Dan
dtaylor is offline   Reply With Quote
Old Mar 29th, 2002, 06:03 PM   #2
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

hope this does it for you... will search all files as prescribed and strip any whole lines that contain the search text anywhere in that line...




Sub strip_files()

search_dir = "c:"
file_type = ".csv"
find_string = "*** Header Line ***"

filesfound = 0

Dim filefound As String
filefound = Dir(search_dir & "*" & file_type)
If filefound = "" Then GoTo end_files
nextfile:
filesfound = filesfound + 1
file1 = search_dir & filefound
file2 = Left(file1, Len(file1) - (Len(file_type) - 1)) & "tmpx"
If Dir(file2) <> "" Then Kill file2
Open file1 For Input As #1
Open file2 For Output As #2
Do Until EOF(1)
Line Input #1, strg
If InStr(1, strg, find_string) = 0 Then Print #2, strg
Loop
Close #1
Close #2
Kill file1

filefound = Dir(search_dir & "*" & file_type)
If filefound <> "" Then GoTo nextfile

end_files:
filefound = Dir(search_dir & "*.tmpx")
Do Until filefound = ""
file1 = search_dir & filefound
file2 = Left(file1, Len(file1) - 5) & file_type
Name file1 As file2
filefound = Dir(search_dir & "*.tmpx")
Loop

MsgBox filesfound & " files processed."
End Sub




daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 06:05 PM   #3
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

ps: configure the first few lines, the first of which should read

search_dir = "c:"
daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 06:06 PM   #4
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

darn, it did it again, what is wrong with this thing! ha ha

should only be on forward slash in the directory name specified.
daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 06:09 PM   #5
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

there is definately something wrong with this site, mail me if you want the code as i submitted it (if it doesn't work from copy & pasting) daley_123@hotmail.com
daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 06:21 PM   #6
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-03-29 17:09, daleyman wrote:
there is definately something wrong with this site, mail me if you want the code as i submitted it (if it doesn't work from copy & pasting) daley_123@hotmail.com
Yes there is the [] double up...known prob
This is getting looked into.....please bere
with us until it gets a fix....


Regards

Ivan
Ivan F Moala is offline   Reply With Quote
Old Mar 29th, 2002, 06:33 PM   #7
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

no problem, thanks.
daleyman is offline   Reply With Quote
Old Apr 1st, 2002, 09:33 AM   #8
dtaylor
Board Regular
 
Join Date: Mar 2002
Location: So Cal
Posts: 380
Default

wow thanks for all the interest. i am sorry it took so long for my reply but i was out of town. i will, now that i am back at work uugh!, give this a go. do appreciate the input. you don't know how much work you have saved more than one person. have a good day.

dan
dtaylor is offline   Reply With Quote
Old Apr 1st, 2002, 10:15 AM   #9
dtaylor
Board Regular
 
Join Date: Mar 2002
Location: So Cal
Posts: 380
Default

success my friend...


Dan
dtaylor 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 10:36 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