+ Reply to Thread
Results 1 to 3 of 3

Help rewriting code to use less memory

Hybrid View

  1. #1
    Registered User
    Join Date
    04-20-2015
    Location
    Norway
    MS-Off Ver
    360
    Posts
    24

    Help rewriting code to use less memory

    I posted this problem a few days ago, here.

    Now that I understand the problem a little better, I’m posting it again (hopefully a little clearer)

    This line in the code causes a “not enough memory” error:
    Sheets("Merged Data").Range(Temp).FormulaR1C1 = _
                    "=OFFSET(Y!R1C[" & -LCA & "],MATCH(RC1,Y!R1C1:R" & LRMERGE & "C1,0)-1,0)"
    Is it possible to do this without using as much memory?
    I’m stuck, so I appreciate all feedback!

    This is the code with the values that result in a memory error. The full code is in the link above.
    Sub Merge_Data()
    'Merges the data (rows) with identical Unique-ID in a new sheet. First X, then Y.
    
    Application.ScreenUpdating = False
    
    Dim LC1 As Long
    Dim LCB As Long
    Dim MySheetName As String
        MySheetName = "Merged Data"
        Sheets("X").Copy After:=Sheets("X")
        ActiveSheet.Name = MySheetName
    	'Sheet "Merged Data" is identical to sheet "X" 
    
            
        LR1 = 138938  		'Last row in sheet "X"
        LR2 = 250106  		'Last row in sheet "Y"
        	
        LC1 = 105			'Last column in sheet "X"
        ColLetter = DA 		'column 105 = DA
        
        LC2 = 45			'Last column in sheet "Y" 	
        
        LCA = 106                   'Last column in sheet "X" + 1 (Finds first empty column in the new sheet "Merged Data")
        LCB = 107			'Last column in sheet "X" + 2 (Finds second empty column in the new sheet "Merged Data")
        ColLetter_2 = DC		'column 107 = DC
        
        LRMERGE = 250106		'The biggest of LR1 and LR2
    
        
            
    
    	Sheets("Merged Data").Range("A1:" & ColLetter & LC1).Value = Sheets("X").Range("A1:" & ColLetter & LC1).Value
            			'Is there any reason to keep this line?
    	
    	
    
    	Temp = "" & ColLetter_2 & "1:" & Cells(LRMERGE, LC1 + LC2).Address
    				'Finds the range where the data from sheet "Y" is inputted (in sheet "Merged Data")
            
    	
    	Sheets("Merged Data").Range(Temp).FormulaR1C1 = _
                    "=OFFSET(Y!R1C[" & -LCA & "],MATCH(RC1,Y!R1C1:R" & LRMERGE & "C1,0)-1,0)"
    				'Looks through column "A" in sheet "Y" to find a match in column "A" in sheet "Merged Data"
    				'If there is a match, the row from "Y" is inputted into Column DC in the matched row (in "Merged Data").
            
    
    	Sheets("Merged Data").Range(Temp).Value = Sheets("Merged Data").Range(Temp).Value
    				'Is there any reason to keep this line?
    
    End Sub
    (I can't attach files for some reason)

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Help rewriting code to use less memory

        ColLetter = DA      'column 105 = DA
    DA needs to be in quotes otherwise it is considered to be an undefined variable.

    Similarly,
        ColLetter_2 = DC        'column 107 = DC
    DC needs to be in quotes

    Again, in the following line, Temp is an undefined variable:
        Sheets("Merged Data").Range(Temp).Value = Sheets("Merged Data").Range(Temp).Value
    If Temp is a Named Range, it needs to be in quotes, thus:
        Sheets("Merged Data").Range("Temp").Value = Sheets("Merged Data").Range(Temp).Value

  3. #3
    Registered User
    Join Date
    04-20-2015
    Location
    Norway
    MS-Off Ver
    360
    Posts
    24

    Re: Help rewriting code to use less memory

    Hi! Thanks for taking the time to reply.

    My post is a mess. I've made a new thread and tried to clean it up.
    http://www.excelforum.com/showthread...06#post4323406

+ 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. Replies: 1
    Last Post: 08-14-2013, 12:01 PM
  2. Cant open VBA code editor out of memory
    By Wade073 in forum Excel General
    Replies: 1
    Last Post: 03-19-2012, 05:33 AM
  3. Rewriting macro recorded code for efficiency
    By jhizon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-30-2011, 01:53 PM
  4. Why This Code Increase Memory Usage
    By LeonX in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2006, 02:32 AM
  5. [SOLVED] How much memory does VBA code occupy?
    By Ozgur Pars in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-12-2006, 02:45 PM
  6. How much memory does VBA code occupy?
    By Ozgur Pars in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2006, 02:09 PM
  7. How much memory does VBA code occupy?
    By Ozgur Pars in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2006, 04:05 AM
  8. Rewriting the code in Pivot table - owc11 version
    By haikramesh in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 04-04-2005, 12:42 PM

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