J
J Laroche
My international preferences are set for a comma as the decimal separator.
However imported data often contains a period as decimal separator, and I
wrote a macro to make the conversion. Unfortunately, contrary to what
happens when the conversion is made by hand with Edit/Replace, cell data
remains as text after the macro has executed.
The macro does:
With ActiveSheet
.Range("E2:M367").Replace What:=".", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
When I do that operation manually (in fact, when I record the macro), a cell
containing -12.80 becomes -12,8. But via macro the cell becomes -12,80,
remains left-aligned and doesn't respond to any number formatting, even by
hand. The only way to make it behave like a number is by double-clicking on
the cell and just hitting Enter. Needless to say this is impractical with
the number of cells I'd need to convert.
I found out that a Paste Special with a multiplication by 1 could convert
the texts to numerical values. So I added:
.Range("C2").Copy ' value 1
.Range("E2:M367").PasteSpecial Paste:=xlAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
Again, this works perfectly by hand, but has no effect via macro.
Finally, I had to resort to:
For Each c In .Range("E2:M367").Cells
If IsNumeric(c.Value) Then c.Value = c.Value + 0
Next
I works, but it's much longer.
Does anybody have a better method?
JL
Mac OS X 10.3.9, Office v.X 10.1.6
However imported data often contains a period as decimal separator, and I
wrote a macro to make the conversion. Unfortunately, contrary to what
happens when the conversion is made by hand with Edit/Replace, cell data
remains as text after the macro has executed.
The macro does:
With ActiveSheet
.Range("E2:M367").Replace What:=".", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
When I do that operation manually (in fact, when I record the macro), a cell
containing -12.80 becomes -12,8. But via macro the cell becomes -12,80,
remains left-aligned and doesn't respond to any number formatting, even by
hand. The only way to make it behave like a number is by double-clicking on
the cell and just hitting Enter. Needless to say this is impractical with
the number of cells I'd need to convert.
I found out that a Paste Special with a multiplication by 1 could convert
the texts to numerical values. So I added:
.Range("C2").Copy ' value 1
.Range("E2:M367").PasteSpecial Paste:=xlAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
Again, this works perfectly by hand, but has no effect via macro.
Finally, I had to resort to:
For Each c In .Range("E2:M367").Cells
If IsNumeric(c.Value) Then c.Value = c.Value + 0
Next
I works, but it's much longer.
Does anybody have a better method?
JL
Mac OS X 10.3.9, Office v.X 10.1.6