View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default VBA Import Convert Data Type from Type 1 to Type 2

Type 2 is a number format, Correct?

1) In VBA you can delare the variable as a number format (Integer, Singel,
Double.
2) In VBA use Val(MyNumber) to convert to a number
3) Use copy statement to copy from oneworkbook to another

Workbooks("A").Sheets("Sheet1").Range(B4").copy _
destination:=Workbooks("B").Sheets("Sheet2").Range ("D5")
4) format workbook B top the format you are looking for


Workbooks("A").Sheets("Sheet1").Range(B4").copy _
destination:=Workbooks("B").Sheets("Sheet2").Range ("D5")
Workbooks("B").Sheets("Sheet2").Range("D5").number format = "#0.00"



"u473" wrote:

I would like to fix the data type in my initial Import step
with VBA in order to have all data type for that field as type 2.
But I read in another post from Tom Ogilvy : "In general, you can't
force a change in type in VBA the way you can in Excel..."
I could accept that if the conversion was applied within the Cell
within the same Sheet,
but I am reading data in workbook A, converting and writing it in
workbook B. What is the work around solution ?
Thank you for your help,
J.P.