+ Reply to Thread
Results 1 to 4 of 4

How can I run VBA code that is on one WorkBook on the data in another Workbook?

  1. #1
    Registered User
    Join Date
    12-25-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2013
    Posts
    77

    How can I run VBA code that is on one WorkBook on the data in another Workbook?

    I set up a control Workbook 1 with code to select Workbook 2 (from Windows Explorer) which contains the data I want to process.
    When Workbook 2 is selected, I have a button on the control Workbook 1 that opens and activates Workbook 2.

    The first thing I want to do is sort Workbook 2 by Column "A" using code that is in the control program, Workbook 1 (which at this point is inactive).

    It won't let me Is there a way?

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: How can I run VBA code that is on one WorkBook on the data in another Workbook?

    Hello.

    >Start by defining two variables:
    Please Login or Register  to view this content.
    >Open the second workbook and assign it to the first variable:
    Please Login or Register  to view this content.
    >Assign the sheet of the second workbook where the data to be sorted is to the other variable:
    Please Login or Register  to view this content.
    >And sort the range by column A:
    Please Login or Register  to view this content.
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  3. #3
    Registered User
    Join Date
    12-25-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2013
    Posts
    77

    Re: How can I run VBA code that is on one WorkBook on the data in another Workbook?

    Thanks for the reply, I'll kept a note of it for the next time. Actually after posting, I realized that what I was doing could better be done using one workbook with two sheets. I used code to copy the second workbook in the a second sheet in the first workbook, and went from there. Still required a lot of research for me since my VBA projects are far and few between. I was doing a project for a friend. I got it working today.

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: How can I run VBA code that is on one WorkBook on the data in another Workbook?

    Since you're so happy, you can -then- click the * at the bottom left of post #2 to say thanks for the help.

+ 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. Copy Data to New Workbook with VBA Code without saving new Workbook
    By SimonCampbell in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-19-2021, 06:53 AM
  2. VBA code to copy data from current workbook to another workbook and send email
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-05-2015, 06:47 AM
  3. [SOLVED] Code to copy data from a closed workbook and paste in active workbook using named range.
    By paullie1912 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 02:38 AM
  4. Help! VBA code to open workbook and populate with data from previous workbook
    By musicman1985 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-20-2014, 11:46 AM
  5. Replies: 5
    Last Post: 01-22-2013, 01:33 AM
  6. Replies: 9
    Last Post: 07-27-2012, 06:16 AM
  7. Paste data from active workbook to another workbook using code.
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2009, 04:44 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