Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
pol pol is offline
external usenet poster
 
Posts: 129
Default to read text tablimited file

Hi all

I have a text tablimited file in c:\excel macros folder with the following
format. Please let me know how I can read that file from that folder and to
store in a vriable

1 Description1
2 Description2
3 Description3
4 Description4



Columns("P:P").Select
Range("P1").Activate

Selection.Replace What:="1", Replacement:="Description1",
LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Selection.Replace What:="2", Replacement:="Description2",
LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

With Regards

Pol


  #2   Report Post  
Posted to microsoft.public.excel.misc
pol pol is offline
external usenet poster
 
Posts: 129
Default to read text tablimited file

if the excel file in P:P range , have the value any one of data in the
textfile 1 or 2, or I want to replace with corresponding description

"pol" wrote:

Hi all

I have a text tablimited file in c:\excel macros folder with the following
format. Please let me know how I can read that file from that folder and to
store in a vriable
code description
1 Description1
2 Description2
3 Description3
4 Description4



Columns("P:P").Select
Range("P1").Activate

Selection.Replace What:="1", Replacement:="Description1",
LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Selection.Replace What:="2", Replacement:="Description2",
LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

With Regards

Pol


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default to read text tablimited file

The code below uses a dailog box to open the tab delimited file. the code
creates a tempory workbook with the tab data and then replaces everyting in
column P according to the Tab file.


Sub Replacetext()

Set ModifySht = ActiveSheet

filetoopen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If filetoopen = False Then
MsgBox ("Cannot Open File - Exiting Macro")
Exit Sub
End If

Set newbk = Workbooks.Add
Set TmpSht = newbk.Sheets(1)

With TmpSht.QueryTables.Add( _
Connection:="TEXT;" & filetoopen, _
Destination:=Range("A1"))
.Name = "tabfile"
.SaveData = True
.AdjustColumnWidth = True
.TextFileParseType = xlDelimited
.TextFileTabDelimiter = True
.Refresh BackgroundQuery:=False
End With


With TmpSht
RowCount = 1
Do While .Range("A" & RowCount) < ""
OldData = .Range("A" & RowCount)
NewsData = .Range("B" & RowCount)

ModifySht.Columns("P").Replace _
What:=OldData, _
Replacement:=NewData, _
LookAt:=xlWhole

RowCount = RowCount + 1
Loop

End With

newbk.Close savechanges:=False
End Sub


"pol" wrote:

if the excel file in P:P range , have the value any one of data in the
textfile 1 or 2, or I want to replace with corresponding description

"pol" wrote:

Hi all

I have a text tablimited file in c:\excel macros folder with the following
format. Please let me know how I can read that file from that folder and to
store in a vriable
code description
1 Description1
2 Description2
3 Description3
4 Description4



Columns("P:P").Select
Range("P1").Activate

Selection.Replace What:="1", Replacement:="Description1",
LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Selection.Replace What:="2", Replacement:="Description2",
LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

With Regards

Pol


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
How do you save an excel file to be read as IBM-type text file ? Dee Franklin Excel Worksheet Functions 2 October 10th 06 02:46 AM
I have a read only xl file, I need it to be read and write drama queen Excel Discussion (Misc queries) 3 July 1st 06 12:25 AM
How can a file be converted from Read-Only to Read/Write Jim in Apopka Excel Discussion (Misc queries) 2 November 19th 05 04:59 PM
"Unable to read file" error message when opening a Excel file that contains a PivotTable report. Tim Marsden Charts and Charting in Excel 2 October 15th 05 02:10 PM
Read Text File into Excel Using VBA Willie T Excel Discussion (Misc queries) 13 January 8th 05 12:37 AM


All times are GMT +1. The time now is 08:22 AM.

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

About Us

"It's about Microsoft Excel"