+ Reply to Thread
Results 1 to 5 of 5

Macro to clear memory Cache

Hybrid View

Howardc1001 Macro to clear memory Cache 06-23-2021, 10:43 PM
6StringJazzer Re: Macro to clear memory... 06-23-2021, 11:07 PM
Howardc1001 Re: Macro to clear memory... 06-23-2021, 11:39 PM
6StringJazzer Re: Macro to clear memory... 06-24-2021, 11:15 AM
Howardc1001 Re: Macro to clear memory... 06-24-2021, 12:53 PM
  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,876

    Macro to clear memory Cache

    I have a macro to import data and perform various other things

    However if I run a second macro to find and replace various data , it cannot perform. I then Close Excel and then run this macro and it does what it needs to do

    The reason for it not running after running the first macro it that there is not enough memory (I have 16 GB of Ram use an I7 3.6 GHZ Processor)

    I am look for code that will clear the Memory cashe and allow me to run the second macro without having to close Excel


    I have tried using the code below at the end of my code to free up memory but it does not clear the memory cashe

    Dim DataObj As New MSForms.DataObject 'empty the clipboard
    DataObj.SetText ""
    DataObj.PutInClipboard

    It would be appreciated if someone could assist me
    Last edited by 6StringJazzer; 06-23-2021 at 11:03 PM. Reason: fixed closing code tag

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,005

    Re: Macro to clear memory Cache

    First, why do you think that memory is the problem? Windows memory caching is a very low-level process and I don't think you can do anything about it in VBA. And I doubt this is your problem.

    However, you may have other problems we need to look at, like effective memory management in your first macro. Please post your code (use CODE tags).

    The code you showed here just puts the null string in the clipboard. The clipboard is almost certainly not using 16GB of memory.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,876

    Re: Macro to clear memory Cache

    Thanks for the reply

    See my first macro which combines several macros


     Sub Update()
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    Clear_Data
    Open_Workbook
    Trim Data
    Remove_Leading_Spaces_CommSheets
    Delete_Rows_UnwantedText
     
     
     AdjustRowHeight
     TrimData
     
     
     Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub
    
    
    
    
    Sub Clear_Data()
    With Sheets("Data Import")
    .UsedRange.ClearContents
     End With
    End Sub
    
    Sub Open_Workbook()
    ChDir "C:\downloads"
    A:
    Dim A     As Variant
    Dim LR As Long
         A = Application.GetOpenFilename(MultiSelect:=True)
        If TypeName(A) = "Boolean" Then Exit Sub
        
        Dim File As Variant
        
        Application.ScreenUpdating = False
       For Each File In A
            With Workbooks.Open(File)
    
         
            With Sheets(1)
                .Range("a1", .Range("Y" & Rows.Count).End(xlUp)).Copy _
                    Destination:=ThisWorkbook.Sheets("Data Import").Range("A" & Rows.Count).End(xlUp)
             .Range("a1:M" & Rows.Count).End(xlUp).UnMerge
    
             
             
            End With
      
            .Close savechanges:=False
        End With
     Next
     Application.ScreenUpdating = True
    End Sub
    
    Sub TrimData()
    On Error Resume Next
    
     [a1:az2000] = Application.Trim([a1:az2000])
    
    End Sub
    
    
    
    
    
     Sub Remove_Leading_Spaces_CommSheets()
          Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
          Dim i As Long, LR As Long, R As Range
          
          
        
            With Sheets("Data Import")
          LR = .Cells(Rows.Count, "A").End(xlUp).Row
          For Each R In .Range("A1:E" & LR)
          On Error Resume Next
          
            R.Value = LTrim(R.Value)
          Next R
        End With
      
       Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic
     End Sub
    
    
    
    Sub Delete_Rows_UnwantedText()
    
    
    
        Const sCOMPLIANCE   As String = "*CONTENTS*"
        Const iEXTRA_ROWS   As Integer = 2
        Const sAUDITORS     As String = "AUDITORS"
    
        Dim rStartCell      As Range
        Dim rEndCell        As Range
    
        With Sheets("Data Import").UsedRange
    
            Set rStartCell = .Cells.Find(What:=sCOMPLIANCE, LookAt:=xlWhole)
    
            If Not rStartCell Is Nothing Then
    
                  Set rEndCell = .Cells.Find(sAUDITORS, LookAt:=xlWhole)
    
                  If Not rEndCell Is Nothing Then
    
                        Set rEndCell = rEndCell.Offset(iEXTRA_ROWS, 0)
    
                        Range(rStartCell, rEndCell).EntireRow.Delete
    
                  Else: MsgBox "The text """ & sAUDITORS & " cannot be located"
    
                  End If
    
            Else: MsgBox "The text """ & sCOMPLIANCE & " cannot be located"
    
            End If
    
        End With
    
    End Sub
    
    
        
            
     
    
    
          
        
      
      
      
    
    
    
    
    Sub AdjustRowHeight()
    Dim LR As Long
    With Sheets("data Import")
    LR = Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("a1:A" & LR).EntireRow.AutoFit
      End With
      
    End Sub

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,005

    Re: Macro to clear memory Cache

    This code isn't doing anything that leaves anything in memory. What exactly happens here: "it cannot perform"? What do you expect and what actually happens? Do you get an error message?

  5. #5
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,876

    Re: Macro to clear memory Cache

    When I run a seperate Macro to Replace Space between numbers, I won't do this. I then close Excel, then open the workbook and the macro runs perfectly.

    I am not sure why this does this

+ 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. Pivot table Cache clear
    By magnus101 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 10-25-2024, 02:06 AM
  2. [SOLVED] Macro to update pivot tables and use the SAME cache instead of repeatedly recreating cache
    By Fowzee1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2015, 11:26 PM
  3. Unable to clear pivot cache without reopening the workbook
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-21-2015, 05:45 AM
  4. VBA Code to Clear Cache
    By VB Nubie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-14-2014, 03:19 PM
  5. Loops - Clear cache/memory problem
    By Jovica in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-09-2013, 10:23 AM
  6. How to clear memory while running a macro
    By Hjahren in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-15-2010, 10:04 AM
  7. clear cache to reduce sheet recalc time
    By pacificwaters in forum Excel General
    Replies: 3
    Last Post: 08-16-2008, 12:15 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