Need Help With Export Code

W

WayneK

Hi. Below is some code I wish to use to export a "modified" csv file.
By "modified" I mean that the csv file uses a semicolon ; as the
seperator
and not a comma. I have found that Excel sometimes misreads csv files
which use commas; especially when original cell entries have dashes in
them
(such as 1-5, 3-8 . . . these are output incorrectly as dates Jan-05,
Mar-08,
etc.)

The code below overcomes any of Excel's misreading issues, placing a
semicolon
as a spacer between fields.

My request is to find a compliment to this code. That is, what VBA
code
could import such a "modified" csv file into a specified range in Excel
?
(Without any semicolons being imported into the Excel cells).

Example: if the ExportModifiedCSV code used January.xls, Sheet 1, range
A18:AG142,
and my desired input range is February.xls, Sheet 2, range B18:AH142.
What code would
do this -- stripping out any semicolons ?

Below is the exporting code. I truly appreciate your help.

WayneK

Sub ExportModifiedCSVFile()
Dim FName As String
Dim fs As Object
Dim ftext As Object
Dim wf As WorksheetFunction
Dim x
Dim i As Long

Application.ScreenUpdating = False
Set wf = WorksheetFunction
FName = ThisWorkbook.Path & "\" & "Temp1.csv"
Set fs = CreateObject("Scripting.FileSystemObject")
Set ftext = fs.CreateTextFile(FName, True, 0)

'workbook January.xls is already open, with Sheet 1 active

With Range("A18:AG142")
For i = 1 To .Rows.Count
x = Join(wf.Transpose(wf.Transpose(.Rows(i))), "; ")
ftext.WriteLine x
Next i
End With
ftext.Close
Set fs = Nothing
Set ftext = Nothing
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top