Hi,
I ran into an unexpected behaviour of the Format function in Excel-vba.
I want to read the content of a cell into a string parameter exactly in the way the user sees this content in his worksheet. To do this, I use the Format function and the cells NumberFormat. If the cell contains a number and the cell format is "General", the Format function returns "Ge0eral" i.s.o the number. So when a number is present in cell A1 and the format of cell A1 is set to "General" the function:
Format(Range("A1").Value, Range("A1".NumberFormat)
returns: Ge0eral.
The same occurs when typing: Format(2016,"General") in the Direct window of the Visual Basic editor.
This problem occurs on two different computers using different releases of Excel.
Can anybody explain this behaviour and/or knows a solution?
Thanks.
I ran into an unexpected behaviour of the Format function in Excel-vba.
I want to read the content of a cell into a string parameter exactly in the way the user sees this content in his worksheet. To do this, I use the Format function and the cells NumberFormat. If the cell contains a number and the cell format is "General", the Format function returns "Ge0eral" i.s.o the number. So when a number is present in cell A1 and the format of cell A1 is set to "General" the function:
Format(Range("A1").Value, Range("A1".NumberFormat)
returns: Ge0eral.
The same occurs when typing: Format(2016,"General") in the Direct window of the Visual Basic editor.
This problem occurs on two different computers using different releases of Excel.
Can anybody explain this behaviour and/or knows a solution?
Thanks.