+ Reply to Thread
Results 1 to 6 of 6

Set Range via Structured Reference get error on first vba run, but not second run

  1. #1
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Set Range via Structured Reference get error on first vba run, but not second run

    I have a macro from a large complex workbook, that allows a user to set a list of cell references, and have that data be exported to another workbook.

    I recently transitioned to starting to using Structured Table references, which saves a lot of time when the layout of the sheets changes, as the code in VBA doesn't have to change to match.

    The issue is that on the first time the macro runs after the workbook is opened, the line setting the Range variable fails if it is a structured reference.
    Please Login or Register  to view this content.
    Where expRng.Cells(i, "D").Value is the cell containing the range reference as a string, ie "CalcsTbl[[#Totals],[$ TOTsav/yr]]"

    If I kill the macro and start again, it works perfectly.

    Note that in the above code, intellisense sets range() to a lowercase word. If I copy the code to any other workbook, intellisense capitalises Range(), and I cannot recreate the bug.

    Here is all the relevant subs, and a small example anonyminised workbook.

    If anyone can suggest things that would cause this, or see any mistakes I'm making, it would be greatly appreciated



    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Set Range via Structured Reference get error on first vba run, but not second run

    Didn't read whole, but my guess...
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: Set Range via Structured Reference get error on first vba run, but not second run

    Quote Originally Posted by jindon View Post
    Didn't read whole, but my guess...
    Please Login or Register  to view this content.
    Actually no. The table reference works like a named range, so it is used without a call to the parent worksheet

  4. #4
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: Set Range via Structured Reference get error on first vba run, but not second run

    Quote Originally Posted by jindon View Post
    Didn't read whole, but my guess...
    Please Login or Register  to view this content.
    Thanks jindon
    This is frustrating.
    Using the sheets reference actually works. I had been under the impression from early use of structured references that it didn't.
    I generalised the code thus:
    Please Login or Register  to view this content.
    And I got rid of the lower case issue by adding
    Please Login or Register  to view this content.
    and then deleting it.

    But none of this explains why
    Please Login or Register  to view this content.
    works on the second run of code, but not on the first run.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Set Range via Structured Reference get error on first vba run, but not second run

    1) Please don't quote full post, unless it is really needed.

    2) That's an Excel... Always better to add a parent object if it is known...

  6. #6
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: Set Range via Structured Reference get error on first vba run, but not second run

    Quote Originally Posted by jindon View Post
    1) Please don't quote full post, unless it is really needed.
    Noted.

    As for the parent issue, it looks like I'll need to expand a few of my data structures to keep the sheets. But one of the reasons I like the structured references was that I have been able to move items from sheet to sheet to suit users without breaking code. I no longer have to tell people to just start again if a warning message comes up, but it would still be helpful if I could understand this better.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Modifying structured reference labels
    By Intermedius in forum Excel General
    Replies: 1
    Last Post: 06-17-2019, 12:05 PM
  2. structured reference
    By kolorina in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-16-2018, 08:46 AM
  3. Structured Reference vs Cell Reference
    By pi3volution in forum Excel General
    Replies: 5
    Last Post: 07-30-2017, 10:28 PM
  4. [SOLVED] Nesting a function in a structured reference
    By Bprime in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 06-16-2017, 11:59 AM
  5. Structured Reference to a Single Table Value
    By mcclanat in forum Excel General
    Replies: 3
    Last Post: 11-08-2014, 04:21 PM
  6. VLookup Structured Reference
    By goss in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-27-2014, 03:47 PM
  7. Structured Reference
    By EccentricScientist in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-03-2014, 04:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1