+ Reply to Thread
Results 1 to 13 of 13

Script removes formulas in the source file.

  1. #1
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Script removes formulas in the source file.

    Dear Excel-specialists,

    I have a question.
    I have a script that opens all source files in a directory (Excel sheet with the same format) and copies the content from a specific range to a destination Excel sheet.
    This script works fine (created with the great support of a member of this forum), but as mentioned in the title, this script also removes the formulas in the source files.

    This even happens with the command --> ActiveWorkbook.Close SaveChanges:=False or --> ActiveWorkbook.Close False
    I checked where the change in the formulas happen, and I think that this is the suspect (.Range("R7:S500").Value = arr ), but I am not quite sure.
    Can anybody help me with this question? Unfortunately, I cannot share the Excel files because this is company confidential information (sorry for that/normally I add examples).

    Please Login or Register  to view this content.

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Script removes formulas in the source file.

    You can try changing this:
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    If things don't change they stay the same

  3. #3
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Script removes formulas in the source file.

    Hi CheeseSandwich,

    Thank you for your help.
    I don't get an error, but now I get an #Verw error in the source file (Dutch message).
    The original file contains formulas, and I would like to copy the value of the formula to the destination file without altering the source file.

    For example
    Original file
    =AANTAL.ALS(F$7:F$500;R25) (output value from the formula 123)

    Destination file
    123

    Please see the attached result.
    Attached Images Attached Images

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Script removes formulas in the source file.

    Try replacing:
    Please Login or Register  to view this content.
    With:
    Please Login or Register  to view this content.
    Last edited by CheeseSandwich; 03-31-2023 at 04:47 AM. Reason: Edited the response

  5. #5
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Script removes formulas in the source file.

    I just did that and:
    - Strange..? This code does not add value (from what I can see).
    - The data is copied, but I keep the #Ref error in the destination file.

    What I would Like to achieve is (as a kind of use case:

    1. Open all Excel-source in a directory. Most preferably at the background (Read Data from a closed Excel file without Opening it)

    2. Copy specific cells with values so they are positioned at top of each column (this code works).
    Refresh_Date = .Range("B1").Value ' Read original source cell data (input varies per opened workbook)
    Department_Name = .Range("B2").Value
    Domain_Owner_Name = .Range("C1").Value


    3. Copy all values from the formulas that exist in the source files (range R7:S500) to the destination file, below the Refresh_Date, Department_Name and Domain_Owner_Name

    4. Add a new column that collects the new data from the next source file, until no files are left.

  6. #6
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Script removes formulas in the source file.

    With attachment
    Attached Images Attached Images

  7. #7
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Script removes formulas in the source file.

    To be fair i updated my post at 09:47 with a different response, i changed it to take the array as values and place it in the destination cell. Was hoping you had not looked at it yet.

  8. #8
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Script removes formulas in the source file.

    Thank you very much for helping me.
    The formulas stay intact/ok now, but I lost my markup (lines, colors, borders and so on).
    Is this easy to fix?

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Script removes formulas in the source file.

    Assuming that you have extracted all the information that you need into the array, I would suggest that you close the source file before you save the array into the target cells.

    So, essentially, as soon as you have gathered the information you want, close the source file … then no harm can come to it.

    Not sure why the Save = False isn't working.

    Obviously can't test this theory, no data.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  10. #10
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Script removes formulas in the source file.

    Maybe the below will produce the result you are looking for on the destination sheet?
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Script removes formulas in the source file.

    It works like a charm!!
    Thank you very much for your fast support and effort!!

    Adding reputation
    Thank you (again) for you help.

  12. #12
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Script removes formulas in the source file.

    You're welcome, thanks for the rep.

  13. #13
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Script removes formulas in the source file.

    Quote Originally Posted by CheeseSandwich View Post
    You're welcome, thanks for the rep.
    No problem (deserved)! :-)

+ 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. script to run the macro from Vb script with out opening the excel file
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2021, 03:33 AM
  2. Importing text file in excel using VBA that removes headers and spaces
    By chfinja in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2014, 10:14 AM
  3. [SOLVED] Opening CSV File & It Removes Spaces From Date Columns?
    By Philb1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-10-2013, 04:20 AM
  4. Replies: 2
    Last Post: 02-27-2008, 04:39 AM
  5. [SOLVED] Save as .csv file removes trailing 00
    By Geir Holme in forum Excel General
    Replies: 2
    Last Post: 09-12-2005, 06:05 AM
  6. [SOLVED] Save as .csv file removes trailing 00
    By Geir Holme in forum Excel General
    Replies: 1
    Last Post: 09-09-2005, 01:05 PM
  7. Renaming File Removes Worksheets
    By Dustin D. Cook in forum Excel General
    Replies: 2
    Last Post: 04-07-2005, 06:06 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