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

  • SEARCH
  • Home
  • 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 8704041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:59:53+00:00 2026-06-13T02:59:53+00:00

I am having problems with calculating numerator and denominator with excel VBA. The num

  • 0

I am having problems with calculating numerator and denominator with excel VBA. The num and den are limited to the quarter in which data was entered in the excel spreadsheet.

Here is an example:
I have two columns in my excel sheet:

Date_data_entered_for each_person   Number of visits to the office
1/1/2009                                            5
1/10/2009                                           6
2/10/2009                                           7
5/12/2009                                           9

Based on this example, I have to calculate “average number of visits” per quarter = sum of visits/number of persons. In this example for first quarter of 2009, the data was entered for 3 persons and the total number of visits were, 5+6+7 = 18, hence the average = 18/3 = 6.

The code I have written is:

Function Visits(target_timeframe)

    Target_Quarter = Format(target_timeframe, "YYYYq")

    For vRow = 2 To 2000

        entered_timeframe = Format(Sheets("sheet1").Range("A" & vRow).Value, "YYYYq")

        Entered_Visits = Sheets("sheet1").Range("B" & vRow).Value 'equals value of column

        If (entered_timeframe = Target_Quarter) Then
            denominator = denominator + 1
            If (Entered_Visits > 0) Then
                numerator = numerator + 1
            End If
        End If
    Next

    If denominator > 0 Then
        Average = numerator / denominator
    Else
        Average = "N/A"
    End If

End Function

I am not able to figure out what is wrong with code. Its not calculating the average. I would be extremely grateful if somebody could help me with this issue.

Thanks for you time!

  • 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-06-13T02:59:55+00:00Added an answer on June 13, 2026 at 2:59 am

    I think that instead of:

    numerator = numerator + 1
    

    You want:

    numerator = numerator + Entered_Visits 
    

    With the current code, you’re simply adding 1 to the numerator each time, when in reality you want to be adding the number of visits to the numerator.

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

Sidebar

Related Questions

I am having problems copying data from my device back to the host. My
I'm having problems correctly calculating tax and discounts per item, mainly because I'm not
I'm having some performance problems where a SQL query calculating the average of a
I am having problems with calculating CRC-16 implementation of a byte array in java.
I'm developing a plane fighter game and I'm having some problems when calculating the
Having problems with a small awk script, Im trying to choose the newest of
Having problems iterating. Problem has to do with const correctness, I think. I assume
Having problems with the combining of two statements in a controller. Both statements work
Im having problems with displaying ONLY some elements ONLY on print page. For example
Im having problems with a method in a class file: public static function getPageLeft($pid)

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.