+ Reply to Thread
Results 1 to 4 of 4

Setting worksheet as apublic varaible

  1. #1
    Registered User
    Join Date
    11-08-2014
    Location
    london
    MS-Off Ver
    2013
    Posts
    49

    Setting worksheet as apublic varaible

    Hi. I have a userform that copies data from one worksheet to another. I have used the following code in the initialise userform to set names for each sheet

    Please Login or Register  to view this content.
    This works fine but I have other actions on the userform like changing a value or saving changes. These cant use shSource or shDest as they are not set publically in the userform. How can I change them to make it useable across the whole userform. I have tried using public but the "" around "sheet2" and "sheet1" mean it cant work. I guess there is something simple I am missing

    Thank you.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Setting worksheet as apublic varaible

    Insert a module and declare public variable in the module as follows:
    Please Login or Register  to view this content.
    Instantiate this public variable in the application load event:
    Please Login or Register  to view this content.

    Now you can refer the worksheets with the shSource and shDest variables

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,991

    Re: Setting worksheet as apublic varaible

    If they only need to be available throughout the userform, add:
    Please Login or Register  to view this content.
    to the top of the userform code module, before any routines, and make sure they are not declared elsewhere.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    11-08-2014
    Location
    london
    MS-Off Ver
    2013
    Posts
    49

    Re: Setting worksheet as apublic varaible

    Many thanks

+ 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. [SOLVED] Trouble Setting Range wit h a Varaible Column
    By CGriffiths1214 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2013, 12:26 PM
  2. Transfering Worksheet varaible from Userform to Module?
    By vin1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2011, 07:34 AM
  3. making actions with a toolbox in a varaible
    By vin1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2011, 04:37 PM
  4. assining a varaible to the value in another sheet.
    By shishi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2005, 06:05 PM
  5. Use varaible for worsheet name in a formule
    By slm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2005, 08:05 AM

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