Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with Simple Function


Hi guys,

Am new to this forum but could do with some help. I've just starte
working in a bank and need to sharpen up on my excel. I'm not new t
programming, but am to VB and its syntax. Also I've never been ver
good at debugging.

Anyway trying to write a simple function that takes a range then count
the number of time a string occurs in it. Heres my code:

Function CountStr(ran As Range, Str As String) As Integer

Dim temp As Integer
temp = 0
For Each x In ran
If x = Str Then temp = temp + 1
End If
Next x

CountStr = temp
End Function


Any ideas of why this is throwing an error, I'm sure its somethin
simple. Any help would be nice.

Thanks

To

--
Tomsk
-----------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...fo&userid=2682
View this thread: http://www.excelforum.com/showthread.php?threadid=40075

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with Simple Function


Good afternoon Tomski

The problem is in your End If line. Take it out and your function wil
work fine.

You function could phrase your If statement like this:

If x = Str Then
temp = temp + 1
End If

or like this:

If x = Str Then temp = temp + 1

but not a combination of the two.

Or you could use the =COUNTIF() function to get the job done

HTH

Dominic

--
dominic
-----------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...fo&userid=1893
View this thread: http://www.excelforum.com/showthread.php?threadid=40075

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with Simple Function


Nice one, Cheers for that!

T


--
Tomski
------------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=400754

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with Simple Function


Hi Tomski

You're welcome. Thanks for the feedback.

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=400754

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
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
Very simple match function help Mike Excel Worksheet Functions 0 March 28th 07 01:12 AM
simple if then function amy Excel Worksheet Functions 4 July 6th 05 05:36 PM
Simple Function Help ~ Please Avram Berman Excel Worksheet Functions 9 November 19th 04 11:01 PM
A simple function Bob Grossman Excel Programming 5 August 30th 03 10:21 AM


All times are GMT +1. The time now is 08:19 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"