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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:56:07+00:00 2026-05-10T16:56:07+00:00

I am writing a UDF for Excel 2007 which I want to pass a

  • 0

I am writing a UDF for Excel 2007 which I want to pass a table to, and then reference parts of that table in the UDF. So, for instance my table called ‘Stock’ may look something like this:

Name            Cost            Items in Stock

Teddy Bear    £10              10

Lollipops         20p              1000

I have a UDF which I want to calculate the total cost of all the items left in stock (the actual example is much more complex which can’t really be done without very complex formula)

Ideally the syntax of for the UDF would look something like

TOTALPRICE(Stock) 

Which from what I can work out would mean the UDF would have the signature

Function TOTALPRICE(table As Range) As Variant 

What I am having trouble with is how to reference the columns of the table and iterate through them. Ideally I’d like to be able to do it referencing the column headers (so something like table[Cost]).

  • 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. 2026-05-10T16:56:08+00:00Added an answer on May 10, 2026 at 4:56 pm

    This is very basic (no pun intended) but it will do what you describe. For larger tables it may become slow as under the hood it’s going back and forth between the macro function and the worksheet, and that kind of activity adds up.

    It assumes that you have one row of headers and one column of names (hence the For loop variables starting from 2).

    There are all kinds of things that might be necessary – we can save those for another question or another round on this one.

    Note that the function returns a ‘Variant’, btw…

    Public Function TotalPrice(table As Range) As Variant  Dim row As Long, col As Long Dim total As Double      For row = 2 To table.Rows.Count         For col = 2 To table.Columns.Count             TotalPrice = TotalPrice + table.Cells(row, col) * table.Cells(row, col + 1)         Next     Next  End Function 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing an iPhone app in which I want to save the user the grief
Writing some docs with code snippets which I want to be copyable to run
Writing htaccess that allows me to remove index.php from the URL can confuse search
Writing documentation in html requires some code examples. What to do with characters that
Writing a client application that sends images to a server via a webservice. As
Writing a SQL query that should return the average charges for a preceding 91
Writing some test scripts in IronPython, I want to verify whether a window is
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
Writing an iPhone app, and I'm getting my data from a REST API that
FYI 1: UDF = User Defined (Worksheet) Function FYI 2: XLL = Excel add-in

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.