+ Reply to Thread
Results 1 to 9 of 9

Loop for setting cell values equal to themselves

  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Loop for setting cell values equal to themselves

    Hi everyone,
    I have a very large workbook that includes a lot of large formulas (approx 40mb). As such, after I update the formulas, I copy/paste values and save the values-only file for distribution. The code I am using is fairly simple (I thought), but is giving me a "Run-time error '1004': Application-defined or object-defined error". Here is my code:

    Please Login or Register  to view this content.
    The code is breaking on the main action line of "Range(Cells(i, 1), Cells(i, EndFormulaCol)).Value = Range(Cells(i, 1), Cells(i, EndFormulaCol)).Value". I have tried it with and without the "s" variable and the Application.StatusBar section that displays the macros progress as a percent of rows completed. Disabling that section doesn't seem to make a difference. The macro seems to break on the same row everytime, but if I change the data slightly it will break on a different row (and continue to break on that row each time). The .value = .value action seems pretty simple and works fine for 1000+ rows until it breaks. Is there some sort of memory issue that could be causing this? Thanks for the help!

    Cross-posted here: http://www.ozgrid.com/forum/showthread.php?t=193619
    Last edited by ugabrew; 03-13-2015 at 09:47 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Loop for setting cell values equal to themselves

    Why not just distribute a PDF?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Re: Loop for setting cell values equal to themselves

    The file includes data that others will sort/filter/resort for their needs, so unfortunately a PDF will not work.

  4. #4
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Re: Loop for setting cell values equal to themselves

    I tested this a few different ways:

    - Looping row by row
    - Looping cell by cell (from left to right, then proceed to the next row)
    - Looping through the sheet using ranges of 100 rows at a time

    All of these seem to break on the same row, with the 3rd method of 100 rows at a time breaking with the 100 row group containing this row. When I looped cell by cell, it keeps breaking on the same cell. I tried to see what is different about that cell, but it looks like all the others. The strange thing is that my cell by cell will break on this cell, but when I open the debugger and press F8 to run that line of code again, it works... but then the next cell breaks. I press F8 and that one works too. So basically it gets to a point where it will not run automatically, but if I use the debugger and retry that line, it will execute in 1 or 2 attempts.

    I'm really confused on this one. Could it be a memory issue, or something else behind the scenes that is preventing the code from running automatically beyond a certain point? I watched the task manager while it ran and the memory usage goes down while it runs, which is what I would expect since it is replacing long formulas with values... until it breaks.

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop for setting cell values equal to themselves


  6. #6
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Re: Loop for setting cell values equal to themselves

    Sorry about that. I just read the rule that I should have provided a link. I've edited the OP to include that.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Loop for setting cell values equal to themselves

    Got merged cells?

  8. #8
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Re: Loop for setting cell values equal to themselves

    Nope, no merged cells in this range.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Loop for setting cell values equal to themselves

    The macro seems to break on the same row everytime,
    Can you duplicate that problem in a small workbook containing the line that fails?

+ 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. setting variable equal to a value in a cell
    By ualdriver in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 02-25-2015, 06:01 AM
  2. [SOLVED] How to make a loop stop running when two values get close to each other instead of equal
    By Clue_Less in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-04-2012, 07:06 PM
  3. [SOLVED] Skip loop if cells equal same values
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-02-2012, 01:19 PM
  4. Setting One Cell Equal to Another
    By ashleys.nl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2011, 12:43 PM
  5. Setting varible to equal values of a # of cells
    By mozart in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2006, 06:32 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