LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VB Newbie - Counting occurences in array

Sub RA()
Dim Cell As Range, UserRange As Range
Dim Surname As Variant, Harray As Variant
Set UserRange = ActiveSheet.UsedRange
Harray = Array("A1", "B2", "C3")
For Each Cell In UserRange
Surname = Cell.Value
For i = 0 To UBound(Harray)
If Harray(i) = HoadEx(Surname) Then
n = n + 1
End If
Next i
Next Cell
End Sub
Function HoadEx(aa)
HoadEx = aa
End Function

works well. So how is yours different?


--
Regards,
Tom Ogilvy


"SJC" wrote in message
...
Thanks for that, I had tried something similar but the Ubound makes more
sense than the way I had tried. However, I have another problem with

nesting
this in another For..Next:

For Each Cell In UserRange
Surname = Cell.Value
For i = 0 To UBound(Harray)
If Harray(i) = HOADEX(Surname) Then
n = n + 1
End If
Next i
MsgBox n
Next Cell

The debugger indicates that the Next Cell is causing a problem. I don't
understand why. I have a very similar piece of code elsewhere that works
without any problems. (I realise the code above doesn't actually achieve
anything at the moment, once I've resolved this problem I will be creating

a
routine to deal with n values 1) Any suggestions? TIA

SJC

"RB Smissaert" wrote in message
...
How about simply:

For i = 0 to Ubound(Harray)
If Harray(i) = "test" then
n = n + 1
End If
Next

Msgbox n

RBS

"SJC" wrote in message
...
I'm sure this is a really basic question but it has me stumped. I'm
taking the text strings in a user-defined range, converting them using

a
custom function and putting the converted string into an array. I now
need to count the number of ocurrences of each string within the array

to
test for duplicates. The conversion runs as follows:

i = 0
For Each cell In UserRange
Surname = cell.Value
Harray(i) = HOADEX(Surname)
i = i + 1
Next cell

Harray is Dim'd as string and HOADEX is the custom function. How do I
count the number of times a given string appears in the array?








 
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
Counting occurences of a name [email protected] Excel Worksheet Functions 3 October 8th 07 12:52 AM
Counting the occurences riomarde Excel Worksheet Functions 1 March 27th 06 09:00 PM
Counting Occurences of Hours of the Day Darren Excel Discussion (Misc queries) 3 July 22nd 05 06:58 PM
Counting Occurences Pete Excel Discussion (Misc queries) 7 May 2nd 05 08:28 PM
Help on counting occurences Krishna[_3_] Excel Programming 3 July 28th 04 04:45 AM


All times are GMT +1. The time now is 09:37 AM.

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"