• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Code-csv file into excel- from general to text

michelcr7

New Member
I have a “.csv” file. Now we would like to copy data from this file into another Excel file. Doing this with my simple macro, I encounter a problem in some columns as I have numbers which are stored there in the format: “0000” and “01234567890”. Pasting the data makes then a “0” or “E09” out of the former source.

If I did that manually, I would do the following:

1.Copy from .csv file
2.Paste > “use text import wizard” > changing the respective fields (LFNR_... and EXTERNAL_ID) from “general” to “text”.
3.Would be happy – everything looks fine

This is current macro:

Code:
ImportFileboxData Macro
'
Dim dateiname As String
dateiname = ThisWorkbook.Worksheets("MAS").Range("E7").Value
'
ThisWorkbook.FollowHyperlink ThisWorkbook.Worksheets("MAS").Range("E8").Value

Range("A2:AL10000").Select
Application.CutCopyMode = False
Selection.Copy
Windows("CreateReports.xlsm").Activate
Sheets("RawData").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Windows(dateiname).Activate
ActiveWorkbook.Close (True)

Windows("CreateReports.xlsm").Activate
Sheets("MAS").Select



Do you know a trick how to paste csv-data into an excel spreadsheet keeping the data okay?
 

If you can't manually, you can't by code …
So the same as you can do manually … (Just activate Macro recorder.)​
 
Michelcr7

Firstly, Welcome to the Chandoo.org Forums

Your post has been cross-posted, which means it has been seen on other websites. This is considered poor practice, as it can waste peoples time, which could be spent elsewhere, especially if you get a solution and don't notify us.

I encourage you to please read the site rules at:
http://forum.chandoo.org/link-forums/new-users-please-read.17/
 
Back
Top