Import from text files, not importing as general or text

exceltm

New Member
Joined
Apr 5, 2010
Messages
32
I have some numbers in a text file, like

6-1
7-12
8-11

These denote business hours, such as 6AM to 1AM. When I do a conversion, or import into Excel, whether I import them as GENERAL or TEXT, it converts them to dates such as 1-Jun, 12-Jul, 11-Aug.

How can I make them import exactly as they are, and not be converted to something else?

I use:

Data | Get External Data from Text | choose my text file | Delimited | Text

However, even though I choose text, it converts it to a date format. In the Data Preview window, it shows it correctly as 6-1, 7-12, 8-11, but once I hit Finish, it converts the numbers to date values.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Edit:Sorry, misread you post.

Make sure the cells you are importing into have no formatting.
 
Last edited:
Upvote 0
Im importing into a blank worksheet from a .txt file.
In the text file, the values are, for example:
6-1
6-1
6-12
6-12


I want them to look the same after the import, not be converted into dates, because they are not dates. 6-1 represents 6am-1am, business hours.

After the import, they are formatted as custom date cells automatically, against my wishes:

Excel 2007<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2><COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0" width=25><COL></COLGROUP><THEAD><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH></TH><TH>E</TH></TR></THEAD><TBODY><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">120</TD><TD style="TEXT-ALIGN: right">1-Jun</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">121</TD><TD style="TEXT-ALIGN: right">1-Jun</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">122</TD><TD style="TEXT-ALIGN: right">12-Jun</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">123</TD><TD style="TEXT-ALIGN: right">12-Jun</TD></TR></TBODY></TABLE>
Sheet2


<TABLE style="BORDER-BOTTOM: black 2px solid; BORDER-LEFT: black 2px solid; PADDING-BOTTOM: 0.4em; BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 0.4em; PADDING-RIGHT: 0.4em; BORDER-COLLAPSE: collapse; BORDER-TOP: black 2px solid; BORDER-RIGHT: black 2px solid; PADDING-TOP: 0.4em" rules=all cellPadding=2 width="85%"><TBODY><TR><TD style="PADDING-BOTTOM: 6px; PADDING-LEFT: 6px; PADDING-RIGHT: 6px; PADDING-TOP: 6px">Worksheet Formulas<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; TEXT-ALIGN: center; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2 width="100%"><THEAD><TR style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH width=10>Cell</TH><TH style="TEXT-ALIGN: left; PADDING-LEFT: 5px">Formula</TH></TR></THEAD><TBODY><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>E120</TH><TD style="TEXT-ALIGN: left">41061</TD></TR><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>E121</TH><TD style="TEXT-ALIGN: left">41061</TD></TR><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>E122</TH><TD style="TEXT-ALIGN: left">41072</TD></TR><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>E123</TH><TD style="TEXT-ALIGN: left">41072</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
 
Upvote 0
The steps you outlined in your original post should work. i.e.,
On the ribbon, Click Data.
Get External Data from Text.
Select your file and click Import.
In Original Data Type, Select Delimited and click Next.
Select the Delimiter and click Next.
In Column Data Format select Text.
Click Finish.
Select input range and click Next.


Plan B
Select the Developer tab
Select Code => Record Macro.
Repeat the above steps.
Click Code => Stop Recording.

Right click the sheet tab and select View Code.
In the Project Window on the left hand side Expand the Module.
Double click Module 1.

Look at the generated code and ensure PreserveFormatting is set to true:
Code:
        .PreserveFormatting = [COLOR=darkblue]True[/COLOR]

Delete previous input and,
Press F5 to run the code.
 
Upvote 0

Forum statistics

Threads
1,223,637
Messages
6,173,488
Members
452,515
Latest member
archcalx

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