PC Review


Reply
Thread Tools Rate Thread

Converting European number formats

 
 
Sarah H.
Guest
Posts: n/a
 
      26th Aug 2010
Hi, all,

I work some with data from Europe and have trouble getting numbers into U.S.
format.

I found a promising looking macro on the web, written by David McRitchie:

http://www.mvps.org/dmcritchie/excel/numconv.htm
-----------------------------
Sub USNumbers()
'David McRitchie 2000-05-10 misc convert text numbers
' under wrong control settings to numbes
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range
Dim origValue As String
Dim newValue As String
On Error Resume Next
For Each cell In Selection.Cells.SpecialCells(xlConstants, xlTextValues)
origValue = cell.Value
newValue = ""
For i = 1 To Len(origValue)
If Mid(origValue, i, 1) = "." Then
newValue = newValue & ","
ElseIf Mid(origValue, i, 1) = "," Then
newValue = newValue & "."
Else
newValue = newValue & Mid(origValue, i, 1)
End If
Next i
On Error Resume Next
cell.Value = CDbl(Trim(newValue))
On Error GoTo 0
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
-----------------------------

But when I try to run it in Excel 2010, I get an error about the For-Loop
not being set. Not sure how to proceed. Any help would be appreciated.

-S

 
Reply With Quote
 
 
 
 
James Ravenswood
Guest
Posts: n/a
 
      26th Aug 2010
Make sure Selection.Cells.SpecialCells(xlConstants, xlTextValues) is
not empty
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      26th Aug 2010
The code only works on text entries in the selection.
If you have selected only numeric values then Excel will balk.
If the amount of data is not extremely large (say under 10,000 cells ) then try the following...
1. Add this line just after Dim newValue as String: "Dim i As Long"
1. Remove (or comment out) the first occurrence of "On Error Resume Next"
2. Change: "For Each cell In Selection.Cells.SpecialCells(xlConstants, xlTextValues)"
To: "For Each cell In Selection.Cells"
The above should allow you to select all numbers, all text or text and numbers.
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware

..
..
..

"Sarah H." <(E-Mail Removed)>
wrote in message
news:i55l3v$5cb$(E-Mail Removed)...
Hi, all,
I work some with data from Europe and have trouble getting numbers into U.S.
format.
I found a promising looking macro on the web, written by David McRitchie:

http://www.mvps.org/dmcritchie/excel/numconv.htm
-----------------------------
Sub USNumbers()
'David McRitchie 2000-05-10 misc convert text numbers
' under wrong control settings to numbes
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range
Dim origValue As String
Dim newValue As String
On Error Resume Next
For Each cell In Selection.Cells.SpecialCells(xlConstants, xlTextValues)
origValue = cell.Value
newValue = ""
For i = 1 To Len(origValue)
If Mid(origValue, i, 1) = "." Then
newValue = newValue & ","
ElseIf Mid(origValue, i, 1) = "," Then
newValue = newValue & "."
Else
newValue = newValue & Mid(origValue, i, 1)
End If
Next i
On Error Resume Next
cell.Value = CDbl(Trim(newValue))
On Error GoTo 0
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
-----------------------------
But when I try to run it in Excel 2010, I get an error about the For-Loop
not being set. Not sure how to proceed. Any help would be appreciated.
-S

 
Reply With Quote
 
Scossa
Guest
Posts: n/a
 
      26th Aug 2010
On 26 Ago, 14:02, "Sarah H." <sa...@example.com> wrote:
> Hi, all,
>
> I work some with data from Europe and have trouble getting numbers into U.S.
> format.
>


Try this code (converts european string "1.234,56" into 1234.56 number
value, "52.725" -> 52725):


Sub USNumbers2()
' by Scossa
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim rng As Range
Dim cell As Range
Dim origValue() As String
Dim newValue As String
Dim i As Long

Set rng = Selection.Cells.SpecialCells(xlCellTypeConstants,
xlTextValues)
If Not rng Is Nothing Then
For Each cell In rng
origValue = Split(Replace(cell.Value, ".", ""), ",")
On Error Resume Next 'if no "," in string
newValue = origValue(0)
newValue = newValue & "." & origValue(1)
On Error GoTo 0
cell.Value = CDbl(Trim(newValue))
Next cell
End If
Set rng = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub


Tnks for your feedback.

Bye!
Scossa
 
Reply With Quote
 
Sarah H.
Guest
Posts: n/a
 
      26th Aug 2010
Great information from all! Thanks very much, guys. I will be on holiday
the next four or five days, but I'll try the solutions and report here when
I'm back.

Sarah H.
--------------
"Scossa" <(E-Mail Removed)> wrote in message
news:9ffdc742-49d0-4439-9217-(E-Mail Removed)...
> On 26 Ago, 14:02, "Sarah H." <sa...@example.com> wrote:
>> Hi, all,
>>
>> I work some with data from Europe and have trouble getting numbers into
>> U.S.
>> format.
>>

>
> Try this code (converts european string "1.234,56" into 1234.56 number
> value, "52.725" -> 52725):
>
>
> Sub USNumbers2()
> ' by Scossa
> Application.ScreenUpdating = False
> Application.Calculation = xlCalculationManual
>
> Dim rng As Range
> Dim cell As Range
> Dim origValue() As String
> Dim newValue As String
> Dim i As Long
>
> Set rng = Selection.Cells.SpecialCells(xlCellTypeConstants,
> xlTextValues)
> If Not rng Is Nothing Then
> For Each cell In rng
> origValue = Split(Replace(cell.Value, ".", ""), ",")
> On Error Resume Next 'if no "," in string
> newValue = origValue(0)
> newValue = newValue & "." & origValue(1)
> On Error GoTo 0
> cell.Value = CDbl(Trim(newValue))
> Next cell
> End If
> Set rng = Nothing
> Application.Calculation = xlCalculationAutomatic
> Application.ScreenUpdating = True
> End Sub
>
>
> Tnks for your feedback.
>
> Bye!
> Scossa


 
Reply With Quote
 
Sarah H.
Guest
Posts: n/a
 
      27th Aug 2010
Scossa, your version of the Ritchie macro works for me. Thank you. It did
get flummoxed when it encountered some text that was an unconverted European
date, though. Here's what that column contents looked like: "26.08.2010".
(I know how to get that into recognized dates via text-to-columns. But I'm
simply reporting that this text confused the macro.)

Anyway, when I select the right columns it works beautifully for my needs.
Thanks again.

Sarah
----
"Scossa" <(E-Mail Removed)> wrote in message
news:9ffdc742-49d0-4439-9217-(E-Mail Removed)...
> On 26 Ago, 14:02, "Sarah H." <sa...@example.com> wrote:
>> Hi, all,
>>
>> I work some with data from Europe and have trouble getting numbers into
>> U.S.
>> format.
>>

>
> Try this code (converts european string "1.234,56" into 1234.56 number
> value, "52.725" -> 52725):
>
>
> Sub USNumbers2()
> ' by Scossa
> Application.ScreenUpdating = False
> Application.Calculation = xlCalculationManual
>
> Dim rng As Range
> Dim cell As Range
> Dim origValue() As String
> Dim newValue As String
> Dim i As Long
>
> Set rng = Selection.Cells.SpecialCells(xlCellTypeConstants,
> xlTextValues)
> If Not rng Is Nothing Then
> For Each cell In rng
> origValue = Split(Replace(cell.Value, ".", ""), ",")
> On Error Resume Next 'if no "," in string
> newValue = origValue(0)
> newValue = newValue & "." & origValue(1)
> On Error GoTo 0
> cell.Value = CDbl(Trim(newValue))
> Next cell
> End If
> Set rng = Nothing
> Application.Calculation = xlCalculationAutomatic
> Application.ScreenUpdating = True
> End Sub
>
>
> Tnks for your feedback.
>
> Bye!
> Scossa


 
Reply With Quote
 
Sarah H.
Guest
Posts: n/a
 
      27th Aug 2010
I wrote:

> Scossa, your version of the Ritchie macro works for me. Thank you. It
> did


Sorry: "McRitchie."

Sarah

 
Reply With Quote
 
Sarah H.
Guest
Posts: n/a
 
      6th Sep 2010
I've been back from vacation for a few days and finally got back to this.
Thanks again to all.
Jim's statement about the code's only working on text entries made me
realize that when
I imported the CSV I left those columns as "general." I just tried again
selecting "text" for
the columns with the European-format numbers, and I found to my delight that
the original
McRitchie macro now worked. Great answers from everybody! Much
appreciated.

Sarah H.

---

"Jim Cone" <(E-Mail Removed)> wrote in message
news:i55n94$6lv$(E-Mail Removed)...
> The code only works on text entries in the selection.
> If you have selected only numeric values then Excel will balk.
> If the amount of data is not extremely large (say under 10,000 cells )
> then try the following...
> 1. Add this line just after Dim newValue as String: "Dim i As Long"
> 1. Remove (or comment out) the first occurrence of "On Error Resume
> Next"
> 2. Change: "For Each cell In
> Selection.Cells.SpecialCells(xlConstants, xlTextValues)"
> To: "For Each cell In Selection.Cells"
> The above should allow you to select all numbers, all text or text and
> numbers.
> --
> Jim Cone
> Portland, Oregon USA
> http://www.mediafire.com/PrimitiveSoftware
>
> .
> .
> .
>
> "Sarah H." <(E-Mail Removed)>
> wrote in message
> news:i55l3v$5cb$(E-Mail Removed)...
> Hi, all,
> I work some with data from Europe and have trouble getting numbers into
> U.S.
> format.
> I found a promising looking macro on the web, written by David McRitchie:
>
> http://www.mvps.org/dmcritchie/excel/numconv.htm
> -----------------------------
> Sub USNumbers()
> 'David McRitchie 2000-05-10 misc convert text numbers
> ' under wrong control settings to numbes
> Application.ScreenUpdating = False
> Application.Calculation = xlCalculationManual
> Dim cell As Range
> Dim origValue As String
> Dim newValue As String
> On Error Resume Next
> For Each cell In Selection.Cells.SpecialCells(xlConstants, xlTextValues)
> origValue = cell.Value
> newValue = ""
> For i = 1 To Len(origValue)
> If Mid(origValue, i, 1) = "." Then
> newValue = newValue & ","
> ElseIf Mid(origValue, i, 1) = "," Then
> newValue = newValue & "."
> Else
> newValue = newValue & Mid(origValue, i, 1)
> End If
> Next i
> On Error Resume Next
> cell.Value = CDbl(Trim(newValue))
> On Error GoTo 0
> Next cell
> Application.Calculation = xlCalculationAutomatic
> Application.ScreenUpdating = True
> End Sub
> -----------------------------
> But when I try to run it in Excel 2010, I get an error about the For-Loop
> not being set. Not sure how to proceed. Any help would be appreciated.
> -S
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing a text file witnh european number formats mtatlow Microsoft Access External Data 1 6th Nov 2009 03:42 PM
Read both US and European Formats =?Utf-8?B?TUZJTkU=?= Microsoft Excel Misc 0 17th Aug 2007 02:00 AM
European date formats =?Utf-8?B?bHlubmllbWlsYW5v?= Microsoft Excel Worksheet Functions 1 13th Sep 2005 05:47 PM
Converting Date to Number formats Steve Microsoft Excel Worksheet Functions 2 7th Dec 2003 03:36 AM
Converting various phone number formats Sean Microsoft Excel Worksheet Functions 1 10th Jul 2003 03:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 AM.