Importing, sorting and exporting a text file via a User Form

chisercfc

New Member
Joined
Dec 9, 2003
Messages
23
3 part question:

1) I need to import a text file to position A1 of sheet 1 of a workbook. There are 20 fields in each row and about 200 rows per file. I then need to sort the text file based on the values in Column A. If the value is "A", I need to write that row to sheet 2, if the value is "B", I need to write it to sheet 3.

2) The files I will import reside at H:\Data\Posted, and have names like XYZMMDDYY.txt, where XYZ is the file type and MMDDYY is the date posted. There are several file types, ABC, NMP, etc., and 20 days worth of data.

3) I need to export sheets 2 & 3 to location H:\Data\Processed. I will use a name like File_2_MMDDYY.txt where "2" is the sheet number and MMDDYY is the date I exported.

Per below, I'd like the above to be accomplished via sub-routine/macro and launched via user controls. Any VBA coding help to accomplish the above would be greatly appreciated if you don't want to mess with the next part.

I want to control the above with a User Form incorporating user controls like drop-downs and buttons. I want 3 drop-downs; Import file type - XYZ, ABC, etc, Date - MMDDYY, defaulting to today but allowing me to change it (maybe use a calendar control), and Export file type - File_2 or File_3. I'd like an Import button, which based on my drop-down choices, goes to H:\Data\Posted and imports a file like XYZ083106.txt to sheet 1, position A1. I'd like a second button, Sort, which would launch the sort described in 1) above, and finally, I'd like a third button, Export, which would export the data on sheets 2 or 3 (depending on the circumstance, so I'd have to be able to choose sheet 2 or 3) per 3) above, again, creating a export file name from the drop-downs.

I'm asking a lot here; I don't even know where to begin. So I'll say thank you in advance for any help.

C
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Please provide some sample data which displays data from your intitial text file taken from H:\Data\Posted. Or at least give some more details. How are your fields delimited? Tab, Comma, Fixed Length?


I'd like a second button, Sort, which would launch the sort described in 1) above, and finally, I'd like a third button, Export, which would export the data on sheets 2 or 3 (depending on the circumstance, so I'd have to be able to choose sheet 2 or 3) per 3) above, again, creating a export file name from the drop-downs.

Just curious. Why do you need the extra steps here between import and export? Does the data actually need to be viewed and edited before exporting? If not, I would just do it in in one step.
 
Upvote 0
Here is a sample record, comma delimited:

BY552BR-67-18Y,930504,00010,1,GC,6630,71,1.94,123456088884,Z22619,QR445,25,10,1HGG,17T,2,2.6,2,I8990T,10

These records are sorted based on the first field.

Yes, it needs to be viewed and possibly edited.
 
Upvote 0

Forum statistics

Threads
1,226,223
Messages
6,189,710
Members
453,566
Latest member
ariestattle

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
Back
Top