Run a function when a specific worksheet is opened.

Phil Payne

Board Regular
Joined
May 17, 2013
Messages
131
Office Version
  1. 365
Platform
  1. Windows
Hello all, its been a while.

I have a function that counts the number of conditionally formatted cells in a row.

When there's been little or no activity on the worksheet the cells holding the count results can be blank or show an error message when next you open the worksheet.

I can double click on a problem cell and then hit return and the function runs ok but I need an automated/semi automated solution.

Can anyone help please?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hello all, its been a while.

I have a function that counts the number of conditionally formatted cells in a row.

When there's been little or no activity on the worksheet the cells holding the count results can be blank or show an error message when next you open the worksheet.

I can double click on a problem cell and then hit return and the function runs ok but I need an automated/semi automated solution.

Can anyone help please?
Try Posting your code here so we can see it.
 
Upvote 0
Hello Anfinsen, sorry for the delay in reply.

Two functions and the 'in-cell' formula:-
:

VBA Code:
Function Dfcolor(ByVal R As Range, ColorVal As Long) As Double
Dim r1 As Range

    Application.Volatile
    Dfcolor = 0
    For Each r1 In R
        If Evaluate("Helper(" & r1.Address() & ")") = ColorVal Then Dfcolor = Dfcolor + 1
    Next r1
    
End Function



VBA Code:
Private Function Helper(ByVal R As Range) As Double
    Helper = R.DisplayFormat.Interior.Color
End Function

In cell code:-

=dfcolor(L9:BV9,255)

I hope you can help.

Thanks.
 
Upvote 0
Hello Anfinsen, sorry for the delay in reply.

Two functions and the 'in-cell' formula:-
:

VBA Code:
Function Dfcolor(ByVal R As Range, ColorVal As Long) As Double
Dim r1 As Range

    Application.Volatile
    Dfcolor = 0
    For Each r1 In R
        If Evaluate("Helper(" & r1.Address() & ")") = ColorVal Then Dfcolor = Dfcolor + 1
    Next r1
   
End Function



VBA Code:
Private Function Helper(ByVal R As Range) As Double
    Helper = R.DisplayFormat.Interior.Color
End Function

In cell code:-

=dfcolor(L9:BV9,255)

I hope you can help.

Thanks.
Hello,
I am not 100% sure if this will fix your issue, but try adding this code, saving the workbook, close and re open to check results.

VBA Code:
Private Sub Workbook_Open()
    Application.Calculate
End Sub
 
Upvote 0
Unfortunately that doesn't work.

I want to get the in cell formula to calculate as soon a the WORKSHEET is opened.

At the moment the cells remain empty until i double click a cell and hit return.

Thanks for trying.

.
 
Upvote 0
i've settled for a semi automated approach.
I've oplace a command button on the worksheet and named it "Refresh" with the following code:
VBA Code:
Private Sub CommandButton7_Click
Worksheets("My_Sheet").calculate
End sub

Thanks for your time.
 
Upvote 0
i've settled for a semi automated approach.
I've oplace a command button on the worksheet and named it "Refresh" with the following code:
VBA Code:
Private Sub CommandButton7_Click
Worksheets("My_Sheet").calculate
End sub

Thanks for your time.
Hey there,
Good to see you found a solution, hitting the F9 Key will also calculate all open worksheets.
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,168
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top