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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:15:13+00:00 2026-05-15T15:15:13+00:00

I’m probably missing something simple, but ListRows.Add is giving me grief. Here’s the function:

  • 0

I’m probably missing something simple, but ListRows.Add is giving me grief. Here’s the function:

Sub addEmployee(employeeName As String, tableToAddTo As ListObject)
   Dim newRow As ListRow

   Set newRow = tableToAddTo.ListRows.Add()
   newRow.Range.Cells(1, 1).Value = employeeName
   tableToAddTo.Sort.Apply
End Sub

In most cases, this works fine. However, whenever the function runs on a certain table in my worksheet, the lines following the call to ListRows.Add are never executed (at least that’s what the debugger indicates) and the row does not get added to the table. Any thoughts/ideas?

UPDATE:

Here’s what I’ve learned since the post. If I feed the Sub with stub data it works fine. For example:

Sub driver() 
    Dim myTable As ListObject 
    Set myTable = getTableObject("myTableName") 
    Call addEmployee("myName", myTable)
End Sub

Note: getTableObject cycles through the worksheets and returns the ListObject with the matching name.

It seems to be an issue dealing with the context in which the code is called. In the case that fails, a formula (Function call) has been placed in various cells of various worksheets. The formula contains references to data in other cells. When the data in the other cells changes, the formula is invoked, which in turn calls the addEmployee Sub that is given above. This is the case that fails.

  • 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-15T15:15:14+00:00Added an answer on May 15, 2026 at 3:15 pm

    It appears that what I was trying to do is not possible.

    When you develop custom functions,
    it’s important to understand a key
    distinction between functions that you
    call from other VBA procedures and
    functions that you use in worksheet
    formulas. Function procedures used in
    worksheet formulas must be passive.
    For example, code within a Function
    procedure cannot manipulate ranges or
    change things on the worksheet. An
    example can help make this clear.

    You might be tempted to write a custom
    worksheet function that changes a
    cell’s formatting. For example, it
    could be useful to have a formula that
    uses a custom function to change the
    color of text in a cell based on the
    cell’s value. Try as you might,
    however, such a function is impossible
    to write. No matter what you do, the
    function won’t change the worksheet.
    Remember, a function simply returns a
    value. It cannot perform actions with
    objects.

    That said, I should point out one
    notable exception. It is possible to
    change the text in a cell comment by
    using a custom VBA function.

    Walkenbach, J. (2007). Microsoft
    Office Excel 2007 Power Programming
    with VBA. John Wiley & Sons, p 280.

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

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Can't you just write your own Sprite that has an… May 16, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer All this talk about recursive function and type is a… May 16, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer Stringing together methods like that is called "chaining." return $this;… May 16, 2026 at 11:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.