+ Reply to Thread
Results 1 to 4 of 4

Amending VBA code to refer to another worksheet in another workbook

  1. #1
    Registered User
    Join Date
    07-04-2023
    Location
    Republic of Ireland
    MS-Off Ver
    Office 365
    Posts
    4

    Question Amending VBA code to refer to another worksheet in another workbook

    Hello. How do I adapt the code below so that it refers to another worksheet in another workbook? Workbook is called "My Health & Nutrition.xlsx" and worksheet is called "Schedule". Code is from Randy Austin's "Excel for Freelancers" youtube channel.

    The code works if I put it into the same workbook but I want to keep my main workbook ("My Health & Nutrition.xlsx") macro free and use my personal macro workbook instead to keep all my VBA code and macros. My "My Health & Nutrition.xlsx" workbook is already quite large and I think it'll slow down too much if I enabled macros on it so I don't want to do that. I would like to adapt the code below so that it refers to the page "Schedule" within my "My Health & Nutrition.xlsx" workbook. When I open my "My Health & Nutrition.xlsx" file, my personal macro workbook opens at the same time. I like to put all my VBA code in my personal macro workbook.

    Code I would like to amend is below.

    Paul Carr

    ___________________________________________

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    _____________________________________
    Last edited by 6StringJazzer; 07-04-2023 at 10:18 PM. Reason: better titles please

  2. #2
    Registered User
    Join Date
    07-04-2023
    Location
    Republic of Ireland
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Amending VBA code to refer to another worksheet in another workbook

    Hi,

    I found something about putting the following code .

    Please Login or Register  to view this content.

    Then putting wks before Range for the rest of the code as in <code>wks.range</code> but it doesn't work for me.

    I'd be grateful if anyone can amend the code in my first post so that it acts on another specific worksheet in another workbook that I want to keep free of VBA.

    Thanks,

    Paul Carr

  3. #3
    Registered User
    Join Date
    07-04-2023
    Location
    Republic of Ireland
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Amending VBA code to refer to another worksheet in another workbook

    StringJazzer . Sorry for the code presentation error. Thanks for making the amendment to my initial post.

  4. #4
    Registered User
    Join Date
    07-04-2023
    Location
    Republic of Ireland
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Amending VBA code to refer to another worksheet in another workbook

    I am on a learning curve regarding VBA. My understanding is that I need to set up a class module. What do I put in this class module? Then, I need to amend my original VBA code to read this class module and to properly link to the correct worksheet. How do I do that?

    Here's some information I got from reddit.com

    You have a problem. You code is event code that has to be in the sheet that it acts on if its going to be triggered by selecting or changing the value of a cell (the two events that you posted.)

    The problem is not what sheet the code acts on, the problem is how the code is triggered.

    The posted code is triggered by actions on that one sheet. It is scoped to the sheet level. i.e. it runs when cells on that sheet are changed or selected, but only that sheet. It won't trigger if a cell in a different sheet is changed.

    It is easy to migrate that to be scoped to the Workbook level, so that the code would be triggered by selecting or changing any cell in the workbook. (Move the code into the ThisWorkbook module). But it won't triggered if a cell in a different workbook is changed.

    What you would need to do is migrate that to a Application level event.

    <links removed>

    The class module that holds the application event can be in the Personal Macro Workbook. And the Personal Macro Workbook's Open event is a good place to put the code that instansizes that class module.

+ 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] Need help in amending code
    By jp16 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-22-2017, 02:07 AM
  2. Amending code to add array
    By dms2228 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2013, 01:45 PM
  3. Need help with amending code
    By ea223 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-20-2013, 01:10 AM
  4. Help Amending a bit of VBA code
    By cldcp00 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2013, 04:48 PM
  5. Amending code
    By khalid79m in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2007, 03:23 PM
  6. Help amending code
    By Steve in forum Excel General
    Replies: 4
    Last Post: 08-17-2005, 11:06 AM
  7. Help with Amending this Code Please
    By [email protected] in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-01-2005, 03:06 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