Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Importing a space-delimited txt. file right-justified into Excel

I have a space-delimited txt. file, whose cells need to be imported right
justified into Excel. The txt. file looks like this:

Barney Fife Mayberry 20.00 15.00 10.00 55.00
Thomas Newark 15.00 10.00 5.00 30.00
Mabel Mattingly Louisville Kentucky 5.00 10.00 5.00 20.00

The names in the example above are not being used, but I do need the 4
columns on the right. I've been using the txt import wizard in Excel 2002,
but it is formatted to import the data left-justified, so i have to manually
fix each line.

Does anyone have any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Importing a space-delimited txt. file right-justified into Excel

I would bring the data into column A and then run a macro to extract the last 4
entries in the line:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim mySplit As Variant
Dim iCtr As Long
Dim cCtr As Long

With ActiveSheet
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))

For Each myCell In myRng.Cells
mySplit = Split(Application.Trim(myCell.Value), " ")
If (UBound(mySplit) - LBound(mySplit) + 1) < 4 Then
MsgBox "not enough pieces for row #: " & myCell.Row
Else
cCtr = 0
For iCtr = UBound(mySplit) - 3 To UBound(mySplit)
cCtr = cCtr + 1
If IsNumeric(mySplit(iCtr)) Then
myCell.Offset(0, cCtr).Value = mySplit(iCtr)
Else
myCell.Offset(0, cCtr).Value = "Error!"
End If
Next iCtr

End If
Next myCell
.Columns(1).Delete
End With

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Mohavedad wrote:

I have a space-delimited txt. file, whose cells need to be imported right
justified into Excel. The txt. file looks like this:

Barney Fife Mayberry 20.00 15.00 10.00 55.00
Thomas Newark 15.00 10.00 5.00 30.00
Mabel Mattingly Louisville Kentucky 5.00 10.00 5.00 20.00

The names in the example above are not being used, but I do need the 4
columns on the right. I've been using the txt import wizard in Excel 2002,
but it is formatted to import the data left-justified, so i have to manually
fix each line.

Does anyone have any suggestions?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,344
Default Importing a space-delimited txt. file right-justified into Excel

Hi,

1. I used the Import Wizard on your data choosing Delimited, with a Space
as the delimiter. All the numbers came in right justified, but it sounds
like your's don't?
2. One way that might convert all the text numbers to numbers would be:
a. Select an empty cell and choose Copy, select all the data and choose
Edit, Paste Special, Add.
b. Or, you might try Ctrl+H, with all the data selected and type a space
(hit spacebar once) in the Find what box and nothing in the Replace with box.
Then click Replace All
3. To deal with the names - Since the name may occupy varing number of
columns, select ALL the resulting output and
Press F5, Special, Constants, and turn off all the options except Text and
click OK.
Press Ctrl+- (Ctrl and the Minus key) and choose Shift cells left.
Remove any unnecesary 0's to the right of your data.

--
Thanks,
Shane Devenshire


"Mohavedad" wrote:

I have a space-delimited txt. file, whose cells need to be imported right
justified into Excel. The txt. file looks like this:

Barney Fife Mayberry 20.00 15.00 10.00 55.00
Thomas Newark 15.00 10.00 5.00 30.00
Mabel Mattingly Louisville Kentucky 5.00 10.00 5.00 20.00

The names in the example above are not being used, but I do need the 4
columns on the right. I've been using the txt import wizard in Excel 2002,
but it is formatted to import the data left-justified, so i have to manually
fix each line.

Does anyone have any suggestions?

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
Dollar sign left justified - data right justified - large space BuzzRogers Excel Discussion (Misc queries) 4 April 4th 23 11:27 AM
Output space-delimited file with quotes around text? Sinc Excel Discussion (Misc queries) 1 December 5th 06 11:02 PM
Importing Comma delimited file Patsy Rogge Excel Discussion (Misc queries) 2 April 20th 06 02:50 PM
Parsing a space delimited file into segments robinsgate Excel Discussion (Misc queries) 6 March 18th 05 09:51 PM
HOW DO I EDIT AN EXISTING FILE TO BE SPACE DELIMITED? cf Excel Discussion (Misc queries) 1 February 18th 05 05:29 PM


All times are GMT +1. The time now is 12:18 AM.

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"