0
votes

I'm using the following Code to import a raw data extract (mysql; output format *.xlsx) from an excel sheet (source) into a sheet (target).

Importing Excel spreadsheet data into another Excel spreadsheet containing VBA

The target sheet is a excel-template contains some macros e.g. to allow users to easily sort data.

All is working very well, except that some data are malformed after import. Its really strange but due to any reason target is not an exact copy of the source sheet. Issues I've for example with date format and decimals.

I've tried several things to tweak the code but failed. I believe that the way how the import in target sheet is handled by code is the reason why it doesnt work.

Now my question is if there exits any other way to import data from excel to excel. Also I'm looking for a solution how I could solve the problem that excel formats all values automatically as text?

Any help would be highly appreciated.

Kind regards

1

1 Answers

0
votes

Try replacing this line

targetSheet.Range("A1", "C10").Value = sourceSheet.Range("A1", "C10").Value

With this

sourceSheet.Range("A1", "C10").Copy
targetSheet.Range("A1", "C10").PasteSpecial

The former only copies the values. The latter copies both values AND its formatting, so things like date formats and number of decimals should be included as well.