Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 96
Default import tx file into excel

I have a txt file of stolen guns, the problem, some have a mak and type field
and some do not so data is not lining up correctly on the ones missing the
fields. What do you do about missing fields in the data? Using 2003 Excel
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default import tx file into excel


If the missing fields are at the start or end of the data string, you
can do something like:


Dim S As String
Dim N As Long
Dim E As Long
Dim Diff As Long
E = 4 ' expected number of delimiters
' give S a test value
S = "a,b,c"
N = Len(S) - Len(Replace(S, ",", ""))
Diff = E - N
If Diff < 0 Then
S = Application.Rept("missing,", Diff) & S ' ADD AT START
'S = S & Application.Rept(",missing", Diff) ' ADD AT END
End If
Debug.Print S


Here, S is the string that you are reading in from the text file. E is
the number of delimiters that are expected in "good" data. The code
the gets the number of delimiters (in this case, commas) in the test
string, and if the number of delimiters does not equal the expected
number of delimiters, it adds "missing" at either the end of the test
string or the beginning of the test string. You can change "missing"
to whatever you want to use for missing data.

If your data is missing fields within the record, at neither the start
or end, then the only way that might be possible to test expected data
types and expected values to attempt to find where the missing fields.
That would be rather complicated and not necessarily very reliable.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Tue, 7 Apr 2009 12:06:04 -0700, Pammy
wrote:

I have a txt file of stolen guns, the problem, some have a mak and type field
and some do not so data is not lining up correctly on the ones missing the
fields. What do you do about missing fields in the data? Using 2003 Excel

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 248
Default import tx file into excel

You will either have to fix the text file or the Excel worksheet after
importing the data...
Fixing Excel would be easier
Select the rows with missing information (Data | Filter)
Press F5 | Special | Visible Cells only
Right Click and insert cells (Shift cells right)... as per requirement
-------------------------------------
Pl. click ''''Yes'''' if this was helpful...



"Pammy" wrote:

I have a txt file of stolen guns, the problem, some have a mak and type field
and some do not so data is not lining up correctly on the ones missing the
fields. What do you do about missing fields in the data? Using 2003 Excel

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Txt file over several excel sheets Tamara Excel Discussion (Misc queries) 2 December 2nd 08 10:51 PM
USING DATA FROM AN EXCEL FILE TO IMPORT INTO ANOTHER Andrew Pickles Excel Worksheet Functions 1 January 17th 07 07:30 PM
How come I can't import an .svc file(Open Office) to Excel file? beezer Excel Discussion (Misc queries) 1 August 28th 06 12:05 AM
How do I import a CSV file to excel lorraine knight Excel Discussion (Misc queries) 4 June 30th 06 05:08 PM
Is there a way to import a pdf file in to Excel jrandall Excel Worksheet Functions 7 April 26th 05 11:10 AM


All times are GMT +1. The time now is 03:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"