+ Reply to Thread
Results 1 to 8 of 8

How to use a Public variant

  1. #1
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    216

    How to use a Public variant

    I want to save a range of numbers so that the range can then be cleared for new values or the old ones can be recovered and put back into the range. I have tried the following code to do this
    Please Login or Register  to view this content.
    This fails at the first step because the variant is not recognized. Where have I gone wrong?
    In the attached sheet the named range OHLabels_Table is V11:X55
    If I Dim ArPercent in the 1sr Sub It accepts the values in the table but I cant figure out how to use it in sub2
    Attached Files Attached Files

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to use a Public variant

    Hi there,

    I'm using Excel 2016.

    In the workbook you posted, I clicked on the "Save Changes" button, manually cleared all of the values from Columns V and X, and then clicked on the "Restore" button - all values were restored.

    It's difficult to understand exactly what you mean when you say:


    because the variant is not recognized

    What sort of error message is being generated?

    Regards,

    Greg M

  3. #3
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: How to use a Public variant

    I am also not getting any errors in 365.

  4. #4
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    216

    Re: How to use a Public variant

    Sorry about the delay in coming ack to you and thanks for your interest.
    What happens when I try to run the SAVE CHANGES button is nothing, there are no error messages.
    When I step the code each line is visited but nothing happens. The Locals window has no record of the Sub or the variant.
    I am not sure if a Public variable would show in the locals window.
    I hope this might give clue as to what might be happening.
    I am running 365
    John

  5. #5
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: How to use a Public variant

    Hi Osprey, what I meant when I said when I wasn't getting any errors, I meant the macros functioned properly and did the job you asked them to do.

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to use a Public variant

    I am not sure if a Public variable would show in the locals window
    Only in the context of that Sub.

    If you want to see it all the time you can use the Watch Window to add a watch in which you can choose All Procedures.
    Right-click the variable definition and choose Add Watch.
    Attached Images Attached Images
    Last edited by ByteMarks; 03-08-2024 at 11:16 AM.

  7. #7
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    216

    Re: How to use a Public variant

    PrizeGotti
    I took your first post to mean that.
    I seem to have solved the problem by creating subs to do the work and using the button_Click code to call them. The public variant then works as wanted. The watch screen showed me that it would work.
    John

  8. #8
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: How to use a Public variant

    Hi John, I'm really confused that you had to do this when it worked fine for myself with the original code in the button events.

+ 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. Does Excel VBA suppoprt the use of variant record types (not variant data types)
    By tfurnivall in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-25-2022, 12:10 PM
  2. Use of variant
    By miles44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2020, 09:08 AM
  3. [SOLVED] Public Constant vs. Public Dim Long
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2020, 03:55 PM
  4. DIM variant
    By miles44 in forum Excel General
    Replies: 2
    Last Post: 02-24-2017, 03:00 PM
  5. [SOLVED] A variable defined as variant or variant array
    By billj in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-14-2016, 05:35 PM
  6. Does setting a variant acting as an array equal to "" accomplish same as "Erase" variant?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2014, 05:59 PM
  7. Variant
    By owl527 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2005, 05:05 PM

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