Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Excel Errors / November 2006

Tip: Looking for answers? Try searching our database.

Replace dot to comma using a macro doesn't work!!!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Whiplash - 20 Nov 2006 14:27 GMT
Hi!

I'm getting nut's at this...
Have a workbook wich is picking up external data (currency) from a website.
It gives me the values with a dot in them (i.e. 12.345)
That's not usable when I want to convert the currency to another one since
Excel can only calculate with comma values.
Ok, so I use search/replace and replace the dots with commas.
Works perfect!
Now I want to make a macro out of it so I don't have to find the columns and
convert manually every time.
I record the macro and do what I normally do when I replace the dots.
Works fine.
I can see the values change the way they should when recording the macro,
but then when I run my macro it doesn't do what it should!!!

For example:
I have a value of 1.031 one at 1.1053 and another of 1.079
When replacing manually the result will be 1,031 and 1,1053 and 1,079 but
when running my recorded macro the end result is 1031 and 11053 and 1079!!!!!!
What's wrong??
Have tried formatting my cells in all different ways but it still ends up
with the same error all the time...

Is it a bug or is it that I should take a course in MS Excel??

Please help me out....

Regards
/Chris
Gary''s Student - 21 Nov 2006 10:10 GMT
Try this:

Sub con()
Dim s As String
s = Selection.Value
s = Application.Substitute(s, ".", ",")
Selection.Value = s
End Sub

Select the cells and then run the sub
Signature

Gary''s Student

> Hi!
>
[quoted text clipped - 26 lines]
> Regards
> /Chris
Gary''s Student - 21 Nov 2006 11:20 GMT
to prevent Excel from re-formatting the value, try:

Sub con2()
Dim s As String
Dim r As Range
   For Each r In Selection
   With r
   s = .Value
   s = Application.Substitute(s, ".", ",")
   .Clear
   .NumberFormat = "@"
   .HorizontalAlignment = xlRight
   .Value = s
   End With
   Next
End Sub

Signature

Gary's Student

> Hi!
>
[quoted text clipped - 26 lines]
> Regards
> /Chris
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.