+ Reply to Thread
Results 1 to 16 of 16

Copying a sheet from closed workbook into active workbook

  1. #1
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Copying a sheet from closed workbook into active workbook

    I have a worksheet 'Lepingu lisa' in file Book1 that I'm trying to modify with a macro to look like the same sheet on Book2 file, but I'm having trouble already with the AV column.
    I have an extra file that I'm trying to use, where the macro should take the value "1". But I get an error with this process.

    So basically I'm trying to use macro for column AV and for table BI:BP

    Never used a macro before, so not that sure what I'm doing so wrong here.

    Or how should I debug this error?

    EDIT: Using this code, but it doesn't seem to work... Only opens the source file and does nothing else. Tho it should copy the sheet and then close it as well.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Fusionista; 02-21-2024 at 10:09 AM.

  2. #2
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    I used this formula in column AV but after activating the macro it only fills the column with the inactive formula. I would have to delete the "=" sign for it to work...

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    Okay, used this code for column AV and it works.

    But how could I possibly add the table BI2:BP11 into the macro? In file Book2
    Copy-paste method doesn't seem to work, if I record the macro. Maybe I'm doing everything wrong there....


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

  4. #4
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    Is there a limit for the macro formula?

    This formula doesn't seen to work there. It's super long, but should work

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    So I've managed to advance a little with my first time macro.

    But I can't get my head around with:

    1. The long formula which I'm trying to use in BL column.

    2. Instead of using hard coded formulas in column AV, could I possibly use an external file where I have selected the areas to use (in this case the cells that have "1" in it)? So when I make changes in the external file it also changes in the macro.

    3. Could I make the macro created data in BI2:BP11 into a table? Surely can, but how?

    4. And maybe the rows with "Aktiivne vakantsus", "Üüritav büroopind kokku" and "Passiivne vakantsus" into Bold.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    Aaaaand once again I've advanced on my very own

    I did figure out 3. and 4.

    But still having a struggle with 1. and 2.

    So help is appreciated
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    Now I could only need some help with my 2. question.

    2. Instead of using hard coded formulas in column AV, could I possibly use an external file where I have selected the areas to use (in this case the cells that have "1" in it)? So when I make changes in the external file it also changes in the macro.

  8. #8
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Macro for using a calculation table

    Just as a suggestion (I'm not sure where you've got to in your task):

    For the "big IF" statement used for cells in column AV, I'd recommend using a lookup table of 2 columns (this table could be on another sheet to keep it out of sight if required). The first column would hold the various text strings that might be included in column D cells [e.g. Aatrium/Fuajee, Kabinet/Büroo etc] and the second column has the value you want to associate with each such text string. Then a short IFERROR + VLOOKUP in the AV cell would generate the required result e.g. IFERROR(VLOOKUP(D3,address of the 2 column lookup table,2,false),"") for cell AV3 would generate the 1 or blank as required. It would make it a lot easier to add additional text strings that require a number 1 to be returned.
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  9. #9
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    Thank You for the suggestion

    I actually do have a seperate file for the list of names. I just don't know how to use it in my macro yet. Open to all suggestions

    Also, if I saved the macro file as PERSONAL.XLSB and someone else is going to use it as well, does he/she has to have the macro file as well?


    EDIT: The code I'm using at the moment is this. Tho I'd like to use the added file. I tried the Sub OpenWorkbook() and Sub CloseWorkbook() but could't get it to work.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Fusionista; 02-21-2024 at 05:57 AM.

  10. #10
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Macro for using a calculation table

    You should be able to programmatically open the second workbook (I think it can be kept hidden if you don't want the user to see it) whenever the main workbook is opened. You would also close it when the main workbook is closed.
    Alternatively, if the second workbook is on a SharePoint or OneDrive location, you can use the http reference to the second workbook in your IF or VLOOKUP formulae without requiring macros. So instead of something like
    Please Login or Register  to view this content.
    you'd use something along the lines of

    Please Login or Register  to view this content.
    The way I get the web address (not sure if there's a better way) is to open both workbooks in Excel online (browser) and make the formulas. This will automatically enter the web addresses.

  11. #11
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Macro for using a calculation table

    But that's the formula that goes in AV column, right?

    My goal, at the moment, is to get the main file take the sheet from 'Tüüpruumide nimestik büroopindadega', add it before sheet 'Lepingu lisa' in the main file and then I could use the given formulas. Right?
    But all I'm able to do with macro code so far is open the 'Tüüpruumide nimestik büroopindadega' file and nothing else happens.

    Any ideas what should I use to perform this task? Open other file -> copy the sheet from there -> close the opened file

    EDIT: I found this code from another forum, but this seems to work with only one specific file I assume: Copy Before:=Workbooks("test.xlsm").Sheets(1). I have many with different names.

    Please Login or Register  to view this content.
    EDIT2: I'm surely doing something wrong here if even this code just opens the other file, doesn't copy the sheet nor close it.

    Please Login or Register  to view this content.
    Last edited by Fusionista; 02-21-2024 at 09:12 AM.

  12. #12
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Copying a sheet from closed workbook into active workbook

    Oh, okay, it does copy the sheet from source file into the active workbook, but it takes the PERSONAL.XLSB, which opens on its own, as the active workbook. And I think it copys the sheet to the source file as well, if it's the active workbook.
    How could I change this?
    Last edited by Fusionista; 02-21-2024 at 10:43 AM.

  13. #13
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Copying a sheet from closed workbook into active workbook

    Can someone please test my macro code.
    I've only altered the source workbook location.

    But I just can't get my head around why does the "Sub CopySheetFromClosedWorkbook()" paste the sheet into PERSONAL.XLSB if I go through the code with F8 and only opens the source workbook if I try running the macro.
    Been messing around with the code for far too long now and can't hard code any other file names there. Only the one that is the source file, as I need to run this macro in many workbooks.
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Copying a sheet from closed workbook into active workbook

    The macro code that you have is contained in the PERSONAL.xlsb workbook. There's a line in that code that says
    Please Login or Register  to view this content.
    , so that is why the worksheet is being copied into the PERSONAL workbook.

    If you want it to be copied into the workbook from which you run the macro, copy the macro into that other workbook and run it from there.

    However, as noted in an earlier post above, if you have the source workbook stored on OneDrive, you wouldn't need to copy the relevant worksheet from one workbook to another workbook for the LOOKUP formulae to work. It is DEFINITELY possible for those formulae in column AV to refer to the OneDrive workbook (you need th ehttp address of the OneDrive workbook for the formulae). I have successfully done this myself- I have a 'tax database' workbook stored on OneDrive. Various solutions to tax questions link back to that workbook, without a need to copy anything into an individual solution workbook. This sounds like what you are trying to do!

  15. #15
    Registered User
    Join Date
    11-01-2023
    Location
    Tallinn, Estonia
    MS-Off Ver
    MS Excel 365
    Posts
    60

    Re: Copying a sheet from closed workbook into active workbook

    Thank You for all the effort. I did some hard coding instead of messing with the macro.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: Copying a sheet from closed workbook into active workbook

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. CUMIPMT calculation doesn't seem to match interest calculation from amortization table
    By cdub39 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 11-28-2021, 08:11 PM
  2. Look up table and calculation
    By Viswateja in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-12-2015, 03:52 PM
  3. Looking for VBA function/macro for a rate table calculation
    By coryhouston in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2014, 06:58 PM
  4. Calculated pivot table field using pivot table data in calculation
    By BrittleStar in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-10-2012, 05:35 PM
  5. Macro to Group/Ungroup a specific Table plus macro to expand/Collapse grouped table.
    By Michell Feitosa in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-04-2012, 08:10 PM
  6. Pivot Table Calculation
    By briandrago in forum Excel General
    Replies: 2
    Last Post: 01-29-2009, 05:27 PM
  7. Doing a calculation in a pivot table
    By Gazzr in forum Excel General
    Replies: 1
    Last Post: 01-07-2009, 03:45 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