Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6327129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:13:25+00:00 2026-05-24T17:13:25+00:00

I execute a VBA code that takes a database, treats it and export it

  • 0

I execute a VBA code that takes a database, treats it and export it into a sheet. This is working fine. However, I have a sheet that produces graphs depending on the data in the particular sheet. The datas does not actualize. I have to enter the cell and click enter to actualize it. I’m pretty sure there is an easier way to do this. Calculation is set to automatic but that doesn’t seem to change anything.

In my cell, I have my own vba function that needs to be updated once the report is done. When I click the cell and then enter, the result is updated but I would like this to be done automatically. I hope this is clearer !

Thanks in advance,

Etienne NOEL

HEre is the code of my function

   Public Function number_of_appearances(term As String, sheet As String, column As Integer) As Integer


Application.Volatile
    Dim number_of_rows As Integer
    Dim appearances As Integer
    Dim row As Integer

    appearances = 0
    row = 1
    number_of_rows = Worksheets(sheet).UsedRange.Rows.Count

    Do While row <= number_of_rows
        If Worksheets(sheet).Cells(row, column).Value = term Then
            appearances = appearances + 1
        End If
         row = row + 1
    Loop


    number_of_appearances = appearances

End Function

A cell example of a user of the function

=number_of_appearances('test';'sheet1'; 3)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:13:26+00:00Added an answer on May 24, 2026 at 5:13 pm

    Sounds like your UDF might not depend on any cells that change value when your DB is processed.
    See This MSDN Link

    Post your UDF (or just its header if you prefer) and an example of its use…

    EDIT:
    Yes, none of the parameters to the UDF are cell references, therefore the UDF is not triggered to recalculate when data on the shet changes.

    You have two choices:
    1. rewrite your UDF to include parameter(s) that reference cells that change value when the DB is processed
    2. make your UDF volitile (include Application.Volatile in the UDF code) WARNING: this can be very inefficient, depending on how many time the UDF is used and how intensive its calculation is

    EDIT 2:
    Heres a refactor of your udf using the first option mentioned:

    Public Function number_of_appearances(term As String, rng As Range) As Integer
        Dim v As Variant
        Dim i As Long, j As Long
        Dim appearances As Long
    
        v = Intersect(rng, rng.Worksheet.UsedRange)
        For j = LBound(v, 2) To UBound(v, 2)
        For i = LBound(v, 1) To UBound(v, 1)
            If v(i, j) = term Then
                appearances = appearances + 1
            End If
        Next i, j
        number_of_appearances = appearances
    
    End Function
    

    use like
    =number_of_appearances("test";Sheet1!C:C)

    EDIT 3:
    If all you are doing is counting number of occurances of a string in a range, consider using
    =COUNTIF(Sheet1!C:C;"test")

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some VBA code that opens a webpage, then calls a javascript function
I have some code that I execute when a slide show presentation begins but
I have the following code that executes a Stored Procedure in Sybase throught VBA.
How does one execute some VBA code periodically, completely automated?
i am adding data from vba excel using adodb into a mysql database everything
I have the following code: CurrentDb.Execute DROP TABLE [ & DatabaseName & ].[ &
I am not an expert on VBA as I've recently started looking into this.
I am copying an VBA code snippet from MSDN that shows me how to
I have the following code for handling userforms on my spreadsheet VBA macros: Option
Is it possible to execute code that is apart of a Form in MS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.