Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default UDF that checks if a cell contains a period.

I have a User Defined function that counts the cells in a range that meet a
certain criteria. The criteria a

1. does not contain a formula
2. is not a number
3. is not blank
4. contains a period.

I can get it to figure out the first three criteria, but I can't figure out
the expression to check to see if the cell contains a period.

Here's what my code looks like:

Function Jonathan(rng As Range) As Long

Dim c As Range

For Each c In rng

If c.HasFormula = False And c.Value < "" And Not IsNumeric(c.Value)
And _
c.Value = "*.*" Then

Jonathan = Jonathan + 1

End If

Next

End Function

It seems to be taking the c.value = "*.*" as a string literal and there
doesn't seem to be a VBA equivalent to the .Net version of the .contains()
method. Any ideas would be greatly appreciated.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default UDF that checks if a cell contains a period.

Check the help file for "Instr" which works like "Find" in a normal formula
(but with the terms reversed, IIRC).

(aircode)
not(iserror((Instr(c.Value,".")))

then the wraparound is because if it doesn't find a period it returns an
error (otherwise it returns a position) so the not/iserror gives you a "true"
if a period is found.

HTH
Keith

"Jonathan Brown" wrote:

I have a User Defined function that counts the cells in a range that meet a
certain criteria. The criteria a

1. does not contain a formula
2. is not a number
3. is not blank
4. contains a period.

I can get it to figure out the first three criteria, but I can't figure out
the expression to check to see if the cell contains a period.

Here's what my code looks like:

Function Jonathan(rng As Range) As Long

Dim c As Range

For Each c In rng

If c.HasFormula = False And c.Value < "" And Not IsNumeric(c.Value)
And _
c.Value = "*.*" Then

Jonathan = Jonathan + 1

End If

Next

End Function

It seems to be taking the c.value = "*.*" as a string literal and there
doesn't seem to be a VBA equivalent to the .Net version of the .contains()
method. Any ideas would be greatly appreciated.

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default UDF that checks if a cell contains a period.

VBA has its own instr function:
if instr(1,c.value, ".", vbtextcompare) 0 then
'it has a dot
...

Or you could use Like:
if c.value like "*.*" then

(I'd use instr.)



Jonathan Brown wrote:

I have a User Defined function that counts the cells in a range that meet a
certain criteria. The criteria a

1. does not contain a formula
2. is not a number
3. is not blank
4. contains a period.

I can get it to figure out the first three criteria, but I can't figure out
the expression to check to see if the cell contains a period.

Here's what my code looks like:

Function Jonathan(rng As Range) As Long

Dim c As Range

For Each c In rng

If c.HasFormula = False And c.Value < "" And Not IsNumeric(c.Value)
And _
c.Value = "*.*" Then

Jonathan = Jonathan + 1

End If

Next

End Function

It seems to be taking the c.value = "*.*" as a string literal and there
doesn't seem to be a VBA equivalent to the .Net version of the .contains()
method. Any ideas would be greatly appreciated.

Thanks.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default UDF that checks if a cell contains a period.

Hi

This should do it:

If c.HasFormula = False And c.Value < "" And Not IsNumeric(c.Value)
And _
InStr(1, c.Value, ".") Then

Regards,
Per


On 6 Feb., 02:09, Jonathan Brown
wrote:
I have a User Defined function that counts the cells in a range that meet a
certain criteria. *The criteria a

1. does not contain a formula
2. is not a number
3. is not blank
4. contains a period.

I can get it to figure out the first three criteria, but I can't figure out
the expression to check to see if the cell contains a period.

Here's what my code looks like:

Function Jonathan(rng As Range) As Long

* * Dim c As Range

* * For Each c In rng

* * * * If c.HasFormula = False And c.Value < "" And Not IsNumeric(c.Value)
And _
* * * * c.Value = "*.*" Then

* * * * * * Jonathan = Jonathan + 1

* * * * End If

* * Next

End Function

It seems to be taking the c.value = "*.*" as a string literal and there
doesn't seem to be a VBA equivalent to the .Net version of the .contains()
method. *Any ideas would be greatly appreciated.

Thanks.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default UDF that checks if a cell contains a period.

The only thing I would add to the other posts is the you do NOT have to
check if the cell is empty... you are requiring the cell's text to have a
period; so if the cell's text has that character in it, then, by definition,
it can't be empty (so the test is not needed).

--
Rick (MVP - Excel)


"Jonathan Brown" wrote in message
...
I have a User Defined function that counts the cells in a range that meet a
certain criteria. The criteria a

1. does not contain a formula
2. is not a number
3. is not blank
4. contains a period.

I can get it to figure out the first three criteria, but I can't figure
out
the expression to check to see if the cell contains a period.

Here's what my code looks like:

Function Jonathan(rng As Range) As Long

Dim c As Range

For Each c In rng

If c.HasFormula = False And c.Value < "" And Not
IsNumeric(c.Value)
And _
c.Value = "*.*" Then

Jonathan = Jonathan + 1

End If

Next

End Function

It seems to be taking the c.value = "*.*" as a string literal and there
doesn't seem to be a VBA equivalent to the .Net version of the .contains()
method. Any ideas would be greatly appreciated.

Thanks.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function neede which checks if a value in a cell is in a defined s LastPhilippe Excel Worksheet Functions 3 May 21st 08 06:32 PM
Code to do edit checks when user moves out of a cell Eric @ BP-EVV Excel Programming 1 April 24th 08 04:33 PM
how excel checks a "#" to express it as a text, check if cell is n kbee Excel Worksheet Functions 3 February 15th 08 05:25 AM
Delete a period in a cell Dar Dar Excel Discussion (Misc queries) 4 June 29th 07 04:10 AM
Period to Period percentage change? cs120 Excel Discussion (Misc queries) 1 September 18th 05 12:05 PM


All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"