Oberon70
Board Regular
- Joined
- Jan 21, 2022
- Messages
- 160
- Office Version
- 365
- Platform
- Windows
Hi,
I have the below code that I used to import a txt file into excel. The problem is that some of the imported data columns need to be defined as txt so that I do not lose the 0 in front of the number.
The example number is 0412870, but when I import it I get 412870.
I have the below code that I used to import a txt file into excel. The problem is that some of the imported data columns need to be defined as txt so that I do not lose the 0 in front of the number.
The example number is 0412870, but when I import it I get 412870.
VBA Code:
Sub ImportTextFileToExcel()
Application.ScreenUpdating = False
fileFilterPattern = "Text Files (*.txt;*.csv), *.txt; *.csv"
fileToOpen = Application.GetOpenFilename(fileFilterPattern)
'"G:\QIA\Short_Tail_Claims\Claims Risk Management\Recoveries\CART Exception Reports\test"
If fileToOpen = False Then
'Input Canceled
MsgBox "no file selected"
Else
Workbooks.OpenText _
Filename:=fileToOpen, _
StartRow:=2, _
DataType:=xlDelimited, _
Comma:=True
Set wbTextImport = ActiveWorkbook
Set wsMaster = ThisWorkbook.Worksheets.Add
Set wsMaster = ThisWorkbook.Worksheets("Data")
wbTextImport.Worksheets(1).Range("A1").CurrentRegion.Copy wsMaster.Range("A3")
wbTextImport.Close False
End If
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
How do I affect only specific data (columns) in the Data that is imported? The delimited in the data file is a comma.
End Sub