LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default a count function

The following works and may be of some use. I have included comments which
should make it understandable

Option Explicit

Sub FindHiddenNumber()
Dim rBlock As Range
Dim c As Range
Dim sTarget As String
Dim sMessage As String
Dim iCount As Integer

'Set the target to search for
sTarget = "56"

'And the range to be searched
Set rBlock = Range("A1:A5")

'Now step through all the cells in the range and look for the target figures
For Each c In rBlock
If InStr(1, CStr(c.Value), sTarget) < 0 Then 'A match is found
sMessage = sMessage & c.Address(False, False) & vbCrLf 'Add it
to result
iCount = iCount + 1 'Count the
occurences
End If
Next

'Prepare the message box with the results
If sMessage = "" Then 'No occurence found
sMessage = "No occurences found"
MsgBox sMessage 'Advise nil result
Else
MsgBox sTarget & " was found " & iCount & " times in the following
cells:" & vbCrLf & _
sMessage 'Message will contain list of cells with target
figures
End If

End Sub


"M" wrote:

I would like to code this :
within a range of cells, containing numbers, I would like to find out :
* how many
* at which location
a given number is located.

Example in which cell(s) is number "56" stored for the following cell values
: 12 456 78541 56 1562

--- 3 times : in cell 2, 4 and 5.

Thanks for the code



 
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
Count function cluckers Excel Discussion (Misc queries) 8 August 17th 09 08:12 PM
Count Function Uma Nandan Excel Discussion (Misc queries) 2 September 24th 08 07:59 PM
count function AJ Patel[_2_] Excel Worksheet Functions 3 March 10th 08 11:22 PM
which count function? y_not Excel Discussion (Misc queries) 6 March 23rd 06 07:24 AM
Count Function Help Josh O. Excel Worksheet Functions 4 July 29th 05 11:04 PM


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