+ Reply to Thread
Results 1 to 17 of 17

Macro Pasting Values Instead of Formulas

  1. #1
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Macro Pasting Values Instead of Formulas

    Hello again! I have a macro that correctly identifies regions in the "raw data" file on Sheet1 and extracts the data to separate worksheets based on the region value (e.g., "Central Region," "Eastern Region"). However, there are formulas that are in Sheet1 that are for some reason being pasted as values in the regional worksheets. Can you help me identify why this is occurring, or more importantly, how to prevent it from occurring? Here is the macro:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro Pasting Values Instead of Formulas

    Perhaps like so:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Hi, Jerry,

    Thanks for the suggestion! I tried the code you proposed, but unfortunately received the following error message: "Run-time error '1004': Unable to get the Transpose property of the WorksheetFunction class." The error was related to this line:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro Pasting Values Instead of Formulas

    The code as a whole works for me when I test it. You'd have to provide a workbook where it doesn't work for me to be able to debug.

    Attach a sample workbook. Make sure there is just enough data to demonstrate the problem.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  5. #5
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Thanks for your quick response, Jerry. I will have to test it a little later today. If it works, I'll definitely come back and mark this case "Solved."

  6. #6
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Here is a sample file. Thanks for taking a look at it!
    TEST.xlsx

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro Pasting Values Instead of Formulas

    Wow, that has me stumped at the moment. In my test workbook, it filters in place on column A and feeds those unique values into an array. In yours, it doesn't.

    I'm guessing your "regions" are static, and as such we can resolve another way:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Well, the regions are more or less static, but there may be times when any given region out of seven may not have data for a given date, and thus would not appear. In that case, I suspect the array would not work. I have a workaround that is working where I just redo the formulas on each sheet, and that can definitely get me by as the report is produced correctly. I was just looking for a more efficient way of running the code so that it wasn't necessary on each sheet.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Pasting Values Instead of Formulas

    @JB
    @bryanmarks

    I inserted JB's Code into the OP's Workbook (TEST.xlsx) and the Code performed without error and appears to give the desired output.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  10. #10
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Hi, John! Did you test the file I uploaded with Jerry's original code or the second code he provided? I'm sure the second code would work, but only if all regions in the array are always present in the data.

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Pasting Values Instead of Formulas

    Hi Bryan

    Attached is your Workbook with JB's Code from Post #2. Appears to perform as expected.
    Attached Files Attached Files

  12. #12
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro Pasting Values Instead of Formulas

    As far as I know you can't transpose discontiguous cells. Easy enough to change to loop through the cells rather than using an array:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  13. #13
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Hi, Rory! Your code worked perfectly! The formulas were all retained on each sheet.

    Thank you and to everyone that responded!

    Bryan

  14. #14
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro Pasting Values Instead of Formulas

    It's actually Jerry's code - I just made a small amendment. Glad it's working.

  15. #15
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Jerry, thanks for the basic code, and Rory, thanks for the tweak to Jerry's code! I do feel rather stupid, however. When I originally posted, I took out the code that referenced additional macros that run on each worksheet after they're extracted. I tried placing them back in the new code, but I'm getting errors which I'm sure are due to my placing them in the wrong place. This is what happens when you're new to VBA and can't always follow the code logic.

    I thought they should go between the WSNew.COLUMNS.AutoFit and the Next rngCell lines in the code, but that didn't work. Can you help me understand where they REALLY should go?

    Thanks!

  16. #16
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro Pasting Values Instead of Formulas

    That seems reasonable but it will depend on how your other routines are written. Do they take a worksheet as an argument, or just work on the active sheet? If the latter, you'd need to add:
    Please Login or Register  to view this content.
    before the line that calls your other routines.

  17. #17
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Macro Pasting Values Instead of Formulas

    Rory, thanks again for the quick response! It turns out the problem was with the macro that was doing conditional formatting, not where I placed the macros or even adding the WSNew.Activate code. It seems that there was a lot of junk conditional formatting that had been saved in the worksheet and I think it was just running out of room to add more. I discovered that if that conditional formatting is just placed on the first sheet to apply to a range of cells, it doesn't have to be in the macro code later. Thanks again for all of your kind help!

    Bryan

+ 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] Converting formulas to values while copying/pasting columns between worksheets (vba)
    By macrorookie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2014, 11:55 AM
  2. Excel crashing when Pasting Formulas as Values
    By XOR LX in forum Excel General
    Replies: 1
    Last Post: 11-08-2013, 11:48 AM
  3. pasting values instead of formulas
    By fabrecass in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2013, 08:22 AM
  4. Copy/Pasting Formulas but only changing certain values in formula
    By Useless_w/_excel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-24-2009, 06:00 PM
  5. Pasting Values with Formulas???
    By mccormij in forum Excel General
    Replies: 2
    Last Post: 04-10-2007, 07:05 AM

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