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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:46:09+00:00 2026-05-25T01:46:09+00:00

I’ve created a function called EnergyPrice with the following code: Here’s the pricetable I’m

  • 0

I’ve created a function called EnergyPrice with the following code:

Here’s the pricetable I’m looking up from

Prijstabel                  
                               fixed           variable 
Startdate   Einddate    gas       electra   gas      electra
                        €/a       €/a       ct/KWh   ct/KWh

1-1-2010    1-7-2010    181,00    235,00     0,11      0,33 
1-7-2010    1-1-2011    362,00    470,00     0,33      1,30 
1-1-2011    1-7-2011    191,00    245,00     0,22      0,65 
1-7-2011    1-1-2012    162,35    208,25     0,19      0,55 
1-1-2012    1-7-2012    324,70    416,50     0,37      1,11 

And here’s the relevant code

Public Enum Energietype
  v_gas = 1
  v_electricity = 2
End Enum

Public Enum FixedOrVariable
  v_fixed = 1
  v_variable = 2
End Enum

Public Function EnergyPrice(PriceDate As Date, E_type As Energietype, variabel As FixedOrVariable) As Variant

Dim PrijsTable As Range
Dim RowNr As Integer
Dim Found As Boolean
Dim KolomNr As Integer

  Set PrijsTable = Range("EnergyPriceTable")
  If PrijsTable.Columns.Count <> 6 Then Err.Raise Number:=vbObjectError + 1000, Description:="No valid valid pricetable defined"
  RowNr = 1
  Found = False

  While Not (Found) And (RowNr <= PriceTable.Rows.Count)
    Found = (PriceTable.Cells(RowNr, 1).Value <= PriceDate) And (PriceTable.Cells(RowNr, 2) > PriceDate)
    If Not (Found) Then RowNr = RowNr + 1
  Wend
  If Found Then
    If E_type = v_gas Then KolomNr = 1
    If E_type = v_elektra Then KolomNr = 2
    If variabel = v_variabel Then KolomNr = KolomNr * 2
    KolomNr = KolomNr + 2
    EnergyPrice = PriceTable.Cells(RowNr, KolomNr).Value
  Else
    EnergyPrice = Empty
  End If
End Function

The question is how do I use the above enums in an Excel spreadsheet? So I can enter a formula like:

enter image description here

If I use the numbers 1,2 the functions works fine, but I want to use the enum names.
Can this be done using only Excel VBA?

  • 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-25T01:46:09+00:00Added an answer on May 25, 2026 at 1:46 am

    If you add the enums to the workbook as defined names, you can pass them into functions and the value that is passed is the actual value you set the enum for. Do this manually or via VBA if you prefer.

    Example:

    ActiveWorkbook.Names.Add Name:="v_gas", RefersToR1C1:="=1"
    ActiveWorkbook.Names.Add Name:="v_fixed", RefersToR1C1:="=2"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.