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 May 7th, 2002, 05:08 PM   #1
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Hi,

I got some code from TSTom to export and import ranges from excel to a text file. This has been working great, but now its time to put the text files to use. Im trying to import the ranges from the text files in a directory to a single sheet to do Data analysis on it. I have most of the code, but i have a few problems. Here is the code first:

Sub DataReport()
With Application.FileSearch
.LookIn = LookIn
.SearchSubFolders = True
.Filename = "*" & Criteria & "*.txt"
.FileType = msoFileTypeExcelWorkbooks
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then

For i = 1 To .FoundFiles.Count

'################################################
'restore from textfile Code
Dim BackUpRange
Dim CurrentBytePosition
Dim FilePathAndName
Dim FileNum
Dim DataSheet As Worksheet

FileNum = FreeFile
CurrentBytePosition = 1

FilePathAndName = .FoundFiles(i)

Open FilePathAndName For Binary As #FileNum
'will restore
Get #1, CurrentBytePosition, BackUpRange
BColCount = AColCount + 4
Sheets("DataReport").Range(Sheets("DataReport").Cells(1, AColCount), Sheets("DataReport").Cells(1000, BColCount)) = BackUpRange
Close FileNum
'################################################
AColCount = BColCount + 1

Next i

End Sub


My first problem: This code works, but it quickly reaches column 256 which is the max in excel. Is there a way to convert the imported range from columns to rows?

Another question is: I export 5 columns of data to the text file. Can i choose which columns i want to import (the 2nd column for example) or do i have to import the WHOLE text file, then do my editing?

I appreciate the help.

Thanks
robfo0 is offline   Reply With Quote
Old May 7th, 2002, 05:25 PM   #2
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Where are AColCount and BColCount declared?

I think simply reversing the reference may be what you're looking for, changing columns to rows that is, but I'm not sure why row 1000 is used for the BColCount:

 
Sheets("DataReport").Range(Sheets("DataReport").Cells(AColCount,1), Sheets("DataReport").Cells(BColCount, 1000)) = BackUpRange



Of course you may want to change the variable names to "ARowCount" and "BRowCount", which would make more sense.

Additionally, TsTom will probably show up and tweak it himself, he's probably better for tackling the 2nd part.

HTH

EDIT:: Is this page format slightly screwed now?
_________________
[b] Mark O'Brien

[ This Message was edited by: Mark O'Brien on 2002-05-07 16:27 ]
Mark O'Brien is offline   Reply With Quote
Old May 7th, 2002, 05:41 PM   #3
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Mark,
Thanks, i will try your solution, but DOH, i forgot i have another problem now. The reason 1000 is in there is because the data backed up is from range a1 to e1000. there are many fields. Looks like i will only be able to import 256 customers at a time if i want to display the 1000 columns

UNLESS, i can select which parts of the data to import. Then i can span customers over rows instead of columns. (cant span over rows right now because i have 1000 fields of data for each customer, excel only allows 256)

Tom help!!

Thanks
robfo0 is offline   Reply With Quote
Old May 7th, 2002, 05:43 PM   #4
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

I was just going to say "Oops, no such thing as 1000 columns in Excel."
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old May 7th, 2002, 07:21 PM   #5
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi Rob.
I read the post and do not understand exactly what you nead help with?
A range saved to a binary file must be restored to the same size range it was backed up from. If you store multiple ranges to one file, you will need to store the starting byte for each range as well.
If you are needing an indexing system for your customer data, maybe use random access files as a working, though somewhat poor, substitute for Access.
When I do my backups, I store all of my ranges to one file. At the beginning of this file I store an array to track my byte positions for each range.

I do not understand why you need a loop to restore you customer data?

How were the ranges backed up?

I do not have the code I initialy wrote for you.

Tom




_________________
Found a solution? If so, please post again so members of this board can spend their time helping others. Better still, edit your topic(intitial post), by tagging on a word or phrase such as, "Problem Solved", or "Resolved". Thanks for being courteous!

[ This Message was edited by: TsTom on 2002-05-07 18:22 ]
Tom Schreiner is offline   Reply With Quote
Old May 8th, 2002, 01:08 AM   #6
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Tom,

thanks for the response, i figured out a way to fix the problem.

The reason i import multiple times is i export text files for each customer. Each customer has a text file and a xls file. i do this to keep files small.

my solution is to import to a worksheet, copy ranges i need, then import the next text file. works

robfo0 is offline   Reply With Quote
Old May 8th, 2002, 02:09 AM   #7
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

As long as it works...
Good news
Tom Schreiner 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 03:38 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