Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Patrice Stewart
 
Posts: n/a
Default VBA Formula Fails to Execute

The procedure below increments a counter (StatusCount) based on the value
contained in range cells. The procedure executes properly when the first
range cell value is changed but will not automatically execute again.

Any assistance would be appreciated.


Function StatusCount(Status)
For Each cell In Worksheets("Sheet1").range("ILStatusRange").Cells
If cell.Value = Status Then
StatusCount = StatusCount + 1
End If
Next
End Function

Function is shown in cell as: =StatusCount("O") where "O" is one of the
six values that occur in the range.


  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Since you embedded the range to check inside the code, excel doesn't know when
to recalculate this function.

It would be better to pass that status code and the range to the function. Then
if either changes, the function will recalculate:

Function StatusCount(Status as string, rng as range) as long
dim cell as range
For Each cell In rng.Cells
If cell.Value = Status Then
StatusCount = StatusCount + 1
End If
Next cell
End Function

And you could call it like:

=statuscount("O",sheet1!Ilstatusrange)

=========
But excel has a function that looks a lot like your function.

Take a look at =countif()

=countif(sheet1!ilstatusrange,"0")
or
=countif(ilstatusrange,"0")
if you're on sheet1 or ilstatusrange is a workbook level name.


Patrice Stewart wrote:

The procedure below increments a counter (StatusCount) based on the value
contained in range cells. The procedure executes properly when the first
range cell value is changed but will not automatically execute again.

Any assistance would be appreciated.

Function StatusCount(Status)
For Each cell In Worksheets("Sheet1").range("ILStatusRange").Cells
If cell.Value = Status Then
StatusCount = StatusCount + 1
End If
Next
End Function

Function is shown in cell as: =StatusCount("O") where "O" is one of the
six values that occur in the range.


--

Dave Peterson
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
Simplify formula Luke Excel Worksheet Functions 37 May 6th 05 07:21 AM
Formula or not? Alan Excel Worksheet Functions 2 February 20th 05 04:26 PM
Match / Vlookup within an Array formula Hari Prasadh Excel Discussion (Misc queries) 3 February 3rd 05 05:37 PM
how do i make a cell date sensitive to execute a formula or input. ebuzz13 Excel Discussion (Misc queries) 2 January 20th 05 09:33 PM
Cell doesn't show formula result - it shows formula (CTRL + ' doe. o0o0o0o Excel Worksheet Functions 6 November 19th 04 04:13 PM


All times are GMT +1. The time now is 05:50 PM.

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

About Us

"It's about Microsoft Excel"