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 8374167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:51:38+00:00 2026-06-09T14:51:38+00:00

This is my first time using VBA for Excel (I usually code Java and

  • 0

This is my first time using VBA for Excel (I usually code Java and C++), and I was hoping to get some tips to start out.

I want to write a macro for a large data set that will proceed through the following list of conditions to provide a dollar result:

  1. Collect unit size from column A (Possible values 0-8)
  2. Determine whether single or family unit from Column B (Single- 1, Family- 0)
  3. Collect utility code from Column C (code for type of product being assessed)

From this information, a new value will be placed in the row which determines utility costs by taking into account unit size, type of unit, and the product in question. I have thought about using nested Select Case or nested conditionals in a loop, but overall I am pretty lost.

  • 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-09T14:51:40+00:00Added an answer on June 9, 2026 at 2:51 pm

    It seems like a worksheet formula might do the trick, but it’s hard to tell without knowing what the calculation is. Below is a user-defined function (UDF) that you would put in a standard module. You would call it from a cell like:

    =computecosts(A2,B2,C2)
    

    Obviously the code would change depending on how your data is laid out and what your calculation is.

    Public Function ComputeCosts(rSize As Range, rFamily As Range, rCode As Range) As Double
    
        Dim lSizeFactor As Long
        Dim lFamilyFactor As Long
        Dim dCodeFactor As Double
        Dim rFound As Range
    
        Const lFAMILY As Long = 0
    
        'Size factor is a function of 0-8, namely adding 1
        lSizeFactor = rSize.Value + 1
    
        'Family factor is computed in code
        If rFamily.Value = lFAMILY Then
            lFamilyFactor = 3
        Else
            lFamilyFactor = 2
        End If
    
        'Code factor is looked up in a different sheet
        Set rFound = Worksheets("Sheet2").Columns(1).Cells.Find(rCode.Value, , xlValues, xlWhole)
        If Not rFound Is Nothing Then
            dCodeFactor = rFound.Offset(0, 1).Value
        End If
    
        'do the math
        ComputeCosts = lSizeFactor * lFamilyFactor * dCodeFactor
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time using jQuery and I am pleased to get my
This is my first time using Google Analytics Ecommerce Tracking to get data for
So this is my first time using cookies and i'm having some trouble setting
This is my first time using a JFrame. I can't get the window to
This is my first time using C#, so I'm very much out of my
This is my first time using VBA in Outlook so please bear with me
This is my first time using Eclipse 3.3.2 to make an application in Java.
This is my first time using JFileChooser in Java and I'm currently attempting to
This is my first time using stackoverflow. I've been unable to find out the
This is my first time using XML documents. What I'm trying to do is

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.