roscoe
Well-known Member
- Joined
- Jun 4, 2002
- Messages
- 1,062
- Office Version
- 365
- Platform
- Windows
- MacOS
Background:
I read in data from a text file line by line ("line_info"). I then extract from that string the first characters up to the first space ("SSC"). The length of SSC is variable, and sometimes SSC is just numbers, and sometimes numbers+text (but always treated in the code as text). I then look to see if that string is included in a list (named range "Filter_list") in the workbook, then I keep the line, otherwise I skip it. The named range has values that are formatted as text but some are in reality straight numbers
Technique:
I use the following VBA code:
Problem:Works if SSC is pure numbers ("12345") but if SSC has characters ("12345-A") the line fails.
How do I fix this? Is there a better way to compare a string to a list of numbers + text?
Thanks
I read in data from a text file line by line ("line_info"). I then extract from that string the first characters up to the first space ("SSC"). The length of SSC is variable, and sometimes SSC is just numbers, and sometimes numbers+text (but always treated in the code as text). I then look to see if that string is included in a list (named range "Filter_list") in the workbook, then I keep the line, otherwise I skip it. The named range has values that are formatted as text but some are in reality straight numbers
Technique:
I use the following VBA code:
Code:
dim Keep as Boolean
dim SSC as string
SSC = Trim(Left(line_info,8)) '// pulls in first 8 characters then removes any excess spaces)
Keep = IsNumeric(WorksheetFunction.Match(SSC, Range("filter_list"))
How do I fix this? Is there a better way to compare a string to a list of numbers + text?
Thanks