View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Shane Devenshire Shane Devenshire is offline
external usenet poster
 
Posts: 857
Default Finding Characters in a String

Hi Bob,

You might try something like this:

Sub DistributeData()
Dim I As Byte
On Error Resume Next
For I = 1 To 30
[A1].CurrentRegion.AutoFilter Field:=2, Criteria1:="?????????????" &
I & "*"
Range([A2], Range("F" &
[A1].SpecialCells(xlLastCell).Row)).SpecialCells(xlCel lTypeVisible).Copy _
Sheets("Unit-" & I).Range("A" & Sheets("Unit-" &
I).[A1].SpecialCells(xlLastCell).Row + 1)
Next I
End Sub

You would need to modify it to work through each sheet of imported data.
This code assumes you have titles at the tops of each of the 30 output
sheets on row 1. It also assumes that there are titles on row 1 of the data
sheets. The code might run faster if you sort the data on the unit numbers
before you run the autofilter. You could do that by using the Text to
Columns command to extract the 2 unit digits to column G and then sort on
that. The On Error Resume Next command is used to handle the case where
there is no item found when the autofilter is run.

Cheers,
Shane Devenshire
Microsoft Excel MVP

"BobS" wrote in message
...
Novice
Excel 2003

Have a large text file (equipment log data) that I import using a macro
created by Chip Pearson (www.cpearson.com) called "ImportBigTextFile" that
I have modified slightly and it works fine.

The text files I'm working with have approx 180,000+ lines of data and the
above macro allows me to import data for 65,536 rows per sheet without
having to break up the original log file.

The imported data is tab-delimited and creates 6 columns of data (A to F)
with a header row:

"Date/Time" "EquipDesc" "Data-1" "Data-2" "Data-3" "Data-4"

Col B (EquipDesc) which has the equipment description is a string of data
similar to this:

"Route 1 Unit 25 Southbound"

I want to be able to find the equipment Unit number (1 - 30 which are
always characters 14 & 15 in the string) in each of the rows in col B on
all the sheets and then copy and paste the entire row into a different
sheet specifically for that Unit number (30 worksheets).


For 180,000+ rows of data, that means I have 3 sheets that already have
65,536 rows of imported data that are sorted by date/time, top-to bottom.
What I need is to find all entries for each Unit number (1-30) on each
sheet then copy those entries into it's own sheet. An example of how to
find text characters within a string would be most helpful.

The workbook already has the worksheets (Unit-1, Unit-2,.....Unit-30) set
up so as I sort down thru the rows of the 3 sheets of the imported data, I
would then do a Case Select on it and then paste that row of data onto
it's corresponding sheet (Unit-1 to Unit-30). I would include counters in
the Case Select statements to increment the row count for each sheet as
each entry is made.

Ideally, sorting the data during input and copying it to it's own
worksheet would be a better method probably but I can't figure out how to
do that. Anyone know of an example that would show that? Since there are
30 Units, the max row entries per worksheet would be around 6,000 rows
(times 30 worksheets) and I would not need the above routine for importing
more than 64K rows.

Thanks for your time, comments and suggestions.

Bob S.