PC Review


Reply
Thread Tools Rate Thread

Can't replace commas with period

 
 
John
Guest
Posts: n/a
 
      5th Oct 2009
Hi Everyone

Below are my codes that I use to clean my data coming from the internet.
They all work except the first one (Find all the commas "," and replace with a
period (.) )
Can anyone tell me why?

Option Explicit

Sub Clean_Data()

Range("J3:L60").Select
Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder _
:=xlByColumns
Range("J3:L60").Select
Cells.Replace What:="$", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByColumns

Range("J3:L60").Select
Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByColumns

' ALT-0160
Range("J3:L60").Select
Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByColumns

End Sub

Regards
John

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      5th Oct 2009
Maybe the values in the cells don't contain commas. Maybe they're just plain
old numbers formatted to show commas (either as the thousands separator or the
decimal point????).

John wrote:
>
> Hi Everyone
>
> Below are my codes that I use to clean my data coming from the internet.
> They all work except the first one (Find all the commas "," and replace with a
> period (.) )
> Can anyone tell me why?
>
> Option Explicit
>
> Sub Clean_Data()
>
> Range("J3:L60").Select
> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder _
> :=xlByColumns
> Range("J3:L60").Select
> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> xlByColumns
>
> Range("J3:L60").Select
> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> xlByColumns
>
> ' ALT-0160
> Range("J3:L60").Select
> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> xlByColumns
>
> End Sub
>
> Regards
> John


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Oct 2009
ps

> Range("J3:L60").Select
> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> xlByColumns


could be re-written:

Range("J3:L60").Replace What:=chr(160), Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByColumns

You could drop the .select's from all your code. And the chr(160) is a little
more self-documenting.


John wrote:
>
> Hi Everyone
>
> Below are my codes that I use to clean my data coming from the internet.
> They all work except the first one (Find all the commas "," and replace with a
> period (.) )
> Can anyone tell me why?
>
> Option Explicit
>
> Sub Clean_Data()
>
> Range("J3:L60").Select
> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder _
> :=xlByColumns
> Range("J3:L60").Select
> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> xlByColumns
>
> Range("J3:L60").Select
> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> xlByColumns
>
> ' ALT-0160
> Range("J3:L60").Select
> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> xlByColumns
>
> End Sub
>
> Regards
> John


--

Dave Peterson
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      5th Oct 2009
Hi Dave
Thank you for your help.
The commas are decimal separators and I need to change it to a period.
I did try manually to type the commas and to see if it would remove them but to
no availed.
If I use the "Find/Replace" menu, I can make it work but I get an error message.
even if I get an error, it still makes the corrections.
Regards
John



"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Maybe the values in the cells don't contain commas. Maybe they're just plain
> old numbers formatted to show commas (either as the thousands separator or the
> decimal point????).
>
> John wrote:
>>
>> Hi Everyone
>>
>> Below are my codes that I use to clean my data coming from the internet.
>> They all work except the first one (Find all the commas "," and replace with
>> a
>> period (.) )
>> Can anyone tell me why?
>>
>> Option Explicit
>>
>> Sub Clean_Data()
>>
>> Range("J3:L60").Select
>> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder _
>> :=xlByColumns
>> Range("J3:L60").Select
>> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart, SearchOrder:= _
>> xlByColumns
>>
>> Range("J3:L60").Select
>> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
>> xlByColumns
>>
>> ' ALT-0160
>> Range("J3:L60").Select
>> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
>> xlByColumns
>>
>> End Sub
>>
>> Regards
>> John

>
> --
>
> Dave Peterson


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Oct 2009
I use the dot for my decimal point and I could change that to a comma with no
trouble.

What error do you get?

Maybe you could try just changing the commas to nothing. Depending on how your
numbers are grouped, it may even be a better choice???

John wrote:
>
> Hi Dave
> Thank you for your help.
> The commas are decimal separators and I need to change it to a period.
> I did try manually to type the commas and to see if it would remove them but to
> no availed.
> If I use the "Find/Replace" menu, I can make it work but I get an error message.
> even if I get an error, it still makes the corrections.
> Regards
> John
>
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Maybe the values in the cells don't contain commas. Maybe they're just plain
> > old numbers formatted to show commas (either as the thousands separator or the
> > decimal point????).
> >
> > John wrote:
> >>
> >> Hi Everyone
> >>
> >> Below are my codes that I use to clean my data coming from the internet.
> >> They all work except the first one (Find all the commas "," and replace with
> >> a
> >> period (.) )
> >> Can anyone tell me why?
> >>
> >> Option Explicit
> >>
> >> Sub Clean_Data()
> >>
> >> Range("J3:L60").Select
> >> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder _
> >> :=xlByColumns
> >> Range("J3:L60").Select
> >> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> >> xlByColumns
> >>
> >> Range("J3:L60").Select
> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> >> xlByColumns
> >>
> >> ' ALT-0160
> >> Range("J3:L60").Select
> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
> >> xlByColumns
> >>
> >> End Sub
> >>
> >> Regards
> >> John

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      5th Oct 2009
Hi Dave
I tried changing commas to nothing,does't work.
The error message is:
"The formula you typed contains an error."
For information about fixing common formula problems, click Help.
with two more line of information.
Regards
John

"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I use the dot for my decimal point and I could change that to a comma with no
> trouble.
>
> What error do you get?
>
> Maybe you could try just changing the commas to nothing. Depending on how
> your
> numbers are grouped, it may even be a better choice???
>
> John wrote:
>>
>> Hi Dave
>> Thank you for your help.
>> The commas are decimal separators and I need to change it to a period.
>> I did try manually to type the commas and to see if it would remove them but
>> to
>> no availed.
>> If I use the "Find/Replace" menu, I can make it work but I get an error
>> message.
>> even if I get an error, it still makes the corrections.
>> Regards
>> John
>>
>> "Dave Peterson" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Maybe the values in the cells don't contain commas. Maybe they're just
>> > plain
>> > old numbers formatted to show commas (either as the thousands separator or
>> > the
>> > decimal point????).
>> >
>> > John wrote:
>> >>
>> >> Hi Everyone
>> >>
>> >> Below are my codes that I use to clean my data coming from the internet.
>> >> They all work except the first one (Find all the commas "," and replace
>> >> with
>> >> a
>> >> period (.) )
>> >> Can anyone tell me why?
>> >>
>> >> Option Explicit
>> >>
>> >> Sub Clean_Data()
>> >>
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder
>> >> _
>> >> :=xlByColumns
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart,
>> >> SearchOrder:= _
>> >> xlByColumns
>> >>
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>> >> SearchOrder:= _
>> >> xlByColumns
>> >>
>> >> ' ALT-0160
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>> >> SearchOrder:= _
>> >> xlByColumns
>> >>
>> >> End Sub
>> >>
>> >> Regards
>> >> John
>> >
>> > --
>> >
>> > Dave Peterson

>
> --
>
> Dave Peterson


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      5th Oct 2009
Hi Dave
I changed the comma symbal , for Chr(44) and it seem to work.
Will need to play with it to be sure.
It's your idea with Chr(160) that made me try that.
Thanks Dave
John
"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I use the dot for my decimal point and I could change that to a comma with no
> trouble.
>
> What error do you get?
>
> Maybe you could try just changing the commas to nothing. Depending on how
> your
> numbers are grouped, it may even be a better choice???
>
> John wrote:
>>
>> Hi Dave
>> Thank you for your help.
>> The commas are decimal separators and I need to change it to a period.
>> I did try manually to type the commas and to see if it would remove them but
>> to
>> no availed.
>> If I use the "Find/Replace" menu, I can make it work but I get an error
>> message.
>> even if I get an error, it still makes the corrections.
>> Regards
>> John
>>
>> "Dave Peterson" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Maybe the values in the cells don't contain commas. Maybe they're just
>> > plain
>> > old numbers formatted to show commas (either as the thousands separator or
>> > the
>> > decimal point????).
>> >
>> > John wrote:
>> >>
>> >> Hi Everyone
>> >>
>> >> Below are my codes that I use to clean my data coming from the internet.
>> >> They all work except the first one (Find all the commas "," and replace
>> >> with
>> >> a
>> >> period (.) )
>> >> Can anyone tell me why?
>> >>
>> >> Option Explicit
>> >>
>> >> Sub Clean_Data()
>> >>
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder
>> >> _
>> >> :=xlByColumns
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart,
>> >> SearchOrder:= _
>> >> xlByColumns
>> >>
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>> >> SearchOrder:= _
>> >> xlByColumns
>> >>
>> >> ' ALT-0160
>> >> Range("J3:L60").Select
>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>> >> SearchOrder:= _
>> >> xlByColumns
>> >>
>> >> End Sub
>> >>
>> >> Regards
>> >> John
>> >
>> > --
>> >
>> > Dave Peterson

>
> --
>
> Dave Peterson


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      5th Oct 2009
Me again
I tried it with fresh data 3 times and it works perfectly.
This is my new line:
Range("J3:L60").Replace what:=Chr(44), Replacement:=Chr(46), LookAt:=xlPart,
SearchOrder:= xlByColumns
Many thanks Dave
Regards
John
"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Dave
> I changed the comma symbal , for Chr(44) and it seem to work.
> Will need to play with it to be sure.
> It's your idea with Chr(160) that made me try that.
> Thanks Dave
> John
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I use the dot for my decimal point and I could change that to a comma with no
>> trouble.
>>
>> What error do you get?
>>
>> Maybe you could try just changing the commas to nothing. Depending on how
>> your
>> numbers are grouped, it may even be a better choice???
>>
>> John wrote:
>>>
>>> Hi Dave
>>> Thank you for your help.
>>> The commas are decimal separators and I need to change it to a period.
>>> I did try manually to type the commas and to see if it would remove them
>>> but to
>>> no availed.
>>> If I use the "Find/Replace" menu, I can make it work but I get an error
>>> message.
>>> even if I get an error, it still makes the corrections.
>>> Regards
>>> John
>>>
>>> "Dave Peterson" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>> > Maybe the values in the cells don't contain commas. Maybe they're just
>>> > plain
>>> > old numbers formatted to show commas (either as the thousands separator or
>>> > the
>>> > decimal point????).
>>> >
>>> > John wrote:
>>> >>
>>> >> Hi Everyone
>>> >>
>>> >> Below are my codes that I use to clean my data coming from the internet.
>>> >> They all work except the first one (Find all the commas "," and replace
>>> >> with
>>> >> a
>>> >> period (.) )
>>> >> Can anyone tell me why?
>>> >>
>>> >> Option Explicit
>>> >>
>>> >> Sub Clean_Data()
>>> >>
>>> >> Range("J3:L60").Select
>>> >> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart,
>>> >> SearchOrder _
>>> >> :=xlByColumns
>>> >> Range("J3:L60").Select
>>> >> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart,
>>> >> SearchOrder:= _
>>> >> xlByColumns
>>> >>
>>> >> Range("J3:L60").Select
>>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>>> >> SearchOrder:= _
>>> >> xlByColumns
>>> >>
>>> >> ' ALT-0160
>>> >> Range("J3:L60").Select
>>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>>> >> SearchOrder:= _
>>> >> xlByColumns
>>> >>
>>> >> End Sub
>>> >>
>>> >> Regards
>>> >> John
>>> >
>>> > --
>>> >
>>> > Dave Peterson

>>
>> --
>>
>> Dave Peterson

>


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Oct 2009
I have no idea why that would matter.

John wrote:
>
> Me again
> I tried it with fresh data 3 times and it works perfectly.
> This is my new line:
> Range("J3:L60").Replace what:=Chr(44), Replacement:=Chr(46), LookAt:=xlPart,
> SearchOrder:= xlByColumns
> Many thanks Dave
> Regards
> John
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi Dave
> > I changed the comma symbal , for Chr(44) and it seem to work.
> > Will need to play with it to be sure.
> > It's your idea with Chr(160) that made me try that.
> > Thanks Dave
> > John
> > "Dave Peterson" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >>I use the dot for my decimal point and I could change that to a comma with no
> >> trouble.
> >>
> >> What error do you get?
> >>
> >> Maybe you could try just changing the commas to nothing. Depending on how
> >> your
> >> numbers are grouped, it may even be a better choice???
> >>
> >> John wrote:
> >>>
> >>> Hi Dave
> >>> Thank you for your help.
> >>> The commas are decimal separators and I need to change it to a period.
> >>> I did try manually to type the commas and to see if it would remove them
> >>> but to
> >>> no availed.
> >>> If I use the "Find/Replace" menu, I can make it work but I get an error
> >>> message.
> >>> even if I get an error, it still makes the corrections.
> >>> Regards
> >>> John
> >>>
> >>> "Dave Peterson" <(E-Mail Removed)> wrote in message
> >>> news:(E-Mail Removed)...
> >>> > Maybe the values in the cells don't contain commas. Maybe they're just
> >>> > plain
> >>> > old numbers formatted to show commas (either as the thousands separator or
> >>> > the
> >>> > decimal point????).
> >>> >
> >>> > John wrote:
> >>> >>
> >>> >> Hi Everyone
> >>> >>
> >>> >> Below are my codes that I use to clean my data coming from the internet.
> >>> >> They all work except the first one (Find all the commas "," and replace
> >>> >> with
> >>> >> a
> >>> >> period (.) )
> >>> >> Can anyone tell me why?
> >>> >>
> >>> >> Option Explicit
> >>> >>
> >>> >> Sub Clean_Data()
> >>> >>
> >>> >> Range("J3:L60").Select
> >>> >> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart,
> >>> >> SearchOrder _
> >>> >> :=xlByColumns
> >>> >> Range("J3:L60").Select
> >>> >> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart,
> >>> >> SearchOrder:= _
> >>> >> xlByColumns
> >>> >>
> >>> >> Range("J3:L60").Select
> >>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
> >>> >> SearchOrder:= _
> >>> >> xlByColumns
> >>> >>
> >>> >> ' ALT-0160
> >>> >> Range("J3:L60").Select
> >>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
> >>> >> SearchOrder:= _
> >>> >> xlByColumns
> >>> >>
> >>> >> End Sub
> >>> >>
> >>> >> Regards
> >>> >> John
> >>> >
> >>> > --
> >>> >
> >>> > Dave Peterson
> >>
> >> --
> >>
> >> Dave Peterson

> >


--

Dave Peterson
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      6th Oct 2009
Hi Dave
>I have no idea why that would matter.<

I wish someone knew, you're telling me it's a fluke,just hope it keeps working.
Regards
John


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have no idea why that would matter.
>
> John wrote:
>>
>> Me again
>> I tried it with fresh data 3 times and it works perfectly.
>> This is my new line:
>> Range("J3:L60").Replace what:=Chr(44), Replacement:=Chr(46), LookAt:=xlPart,
>> SearchOrder:= xlByColumns
>> Many thanks Dave
>> Regards
>> John
>> "John" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Hi Dave
>> > I changed the comma symbal , for Chr(44) and it seem to work.
>> > Will need to play with it to be sure.
>> > It's your idea with Chr(160) that made me try that.
>> > Thanks Dave
>> > John
>> > "Dave Peterson" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >>I use the dot for my decimal point and I could change that to a comma with
>> >>no
>> >> trouble.
>> >>
>> >> What error do you get?
>> >>
>> >> Maybe you could try just changing the commas to nothing. Depending on how
>> >> your
>> >> numbers are grouped, it may even be a better choice???
>> >>
>> >> John wrote:
>> >>>
>> >>> Hi Dave
>> >>> Thank you for your help.
>> >>> The commas are decimal separators and I need to change it to a period.
>> >>> I did try manually to type the commas and to see if it would remove them
>> >>> but to
>> >>> no availed.
>> >>> If I use the "Find/Replace" menu, I can make it work but I get an error
>> >>> message.
>> >>> even if I get an error, it still makes the corrections.
>> >>> Regards
>> >>> John
>> >>>
>> >>> "Dave Peterson" <(E-Mail Removed)> wrote in message
>> >>> news:(E-Mail Removed)...
>> >>> > Maybe the values in the cells don't contain commas. Maybe they're just
>> >>> > plain
>> >>> > old numbers formatted to show commas (either as the thousands separator
>> >>> > or
>> >>> > the
>> >>> > decimal point????).
>> >>> >
>> >>> > John wrote:
>> >>> >>
>> >>> >> Hi Everyone
>> >>> >>
>> >>> >> Below are my codes that I use to clean my data coming from the
>> >>> >> internet.
>> >>> >> They all work except the first one (Find all the commas "," and
>> >>> >> replace
>> >>> >> with
>> >>> >> a
>> >>> >> period (.) )
>> >>> >> Can anyone tell me why?
>> >>> >>
>> >>> >> Option Explicit
>> >>> >>
>> >>> >> Sub Clean_Data()
>> >>> >>
>> >>> >> Range("J3:L60").Select
>> >>> >> Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart,
>> >>> >> SearchOrder _
>> >>> >> :=xlByColumns
>> >>> >> Range("J3:L60").Select
>> >>> >> Cells.Replace What:="$", Replacement:="", LookAt:=xlPart,
>> >>> >> SearchOrder:= _
>> >>> >> xlByColumns
>> >>> >>
>> >>> >> Range("J3:L60").Select
>> >>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>> >>> >> SearchOrder:= _
>> >>> >> xlByColumns
>> >>> >>
>> >>> >> ' ALT-0160
>> >>> >> Range("J3:L60").Select
>> >>> >> Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart,
>> >>> >> SearchOrder:= _
>> >>> >> xlByColumns
>> >>> >>
>> >>> >> End Sub
>> >>> >>
>> >>> >> Regards
>> >>> >> John
>> >>> >
>> >>> > --
>> >>> >
>> >>> > Dave Peterson
>> >>
>> >> --
>> >>
>> >> Dave Peterson
>> >

>
> --
>
> Dave Peterson


 
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
Replace period and single space with period and two spaces in MS W Dougmeister Microsoft Word Document Management 6 16th Nov 2009 01:02 PM
Replace Inverted Commas FARAZ QURESHI Microsoft Word Document Management 3 27th May 2009 03:24 PM
Count Commas and Replace mattc66 via AccessMonster.com Microsoft Access VBA Modules 5 7th Jun 2006 10:46 PM
find and replace - replace data in rows to separated by commas =?Utf-8?B?bXNka2Vy?= Microsoft Excel Worksheet Functions 1 15th Apr 2006 01:00 AM
Replace dot with commas banavas Microsoft Excel Programming 2 13th Oct 2004 01:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:12 AM.