range.find wont find single "," comma occurance

romanemul

New Member
Joined
Jul 22, 2016
Messages
35
Hi community

my sub wont find single occurence of "," only when i type additional comma it started to work.
So only cells with 2 and more occurances of the comma character are processed correctly.


Code:
Sub proc()


Dim inp As Range
Dim outp As Range


Cells(1, 7).Activate
Set inp = ActiveCell.Find(What:=",")


End Sub

inp always returns Nothing

any help would be appreciated
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
so the , is always in the activecell? try:

Code:
If Instr(Cells(1,7).Value,",")>0 Then Set inp = Cells(1,7)
 
Upvote 0
thanks . instr method worked . however i still want to know where is the problem with the find method.
something tells me it had something to do with the excel autoformat feature

So bump.
 
Upvote 0
what was an example of a piece of text where it would not pick up the ","?
 
Upvote 0
What makes you think it is not being found? It seems to work for me.

Sub h()
Dim inp As Range
Dim outp As Range

Cells(1, 7).Activate
Set inp = ActiveCell.Find(What:=",")

MsgBox "Found it = " & Not inp Is Nothing

End Sub


Mark
 
Last edited:
Upvote 0
Mark your code return same results. only returns true when 2+ commas appear.
What makes you think it is not being found? It seems to work for me.

Sub h()
Dim inp As Range
Dim outp As Range

Cells(1, 7).Activate
Set inp = ActiveCell.Find(What:=",")

MsgBox "Found it = " & Not inp Is Nothing

End Sub


Mark
 
Upvote 0
its a cell whose purpose is to detect if the number has comma in it. so i throw in there random numbers

like 100,000? but is that formatted in accounting style or it it an actual ","?
 
Upvote 0
Mark your code return same results. only returns true when 2+ commas appear.


I was assuming a comma insterted as an actual string value. If the comma is there because of cell formatting, for instance, the cell displays 1,234 but the formula bar shows 1234, then you'll need to specify the LookIn parameter.

<font face=Courier New>**<SPAN style="color:#00007F">Set</SPAN> inp = ActiveCell.Find(What:=",", LookIn:=xlValues)</FONT>
 
Upvote 0
i have tried many ways and many formats. Tried changing variants, objects , ranges. checked different find method parameters and even recorded formula returns wrong results.

Few hours ago this function looked totaly trivial to me until i found the comma problem.

I think i return to the instr function until then
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top