1

i need help here . my PC memory ram usage starts to increases gradually after that sub is run, until it is used completely and the system crashes ,

the code only to copy range from sheet and paste to other sheet

i use windows 10 , and the ram is 16 and i try with 32 ram also the same issue happen to me

the code is here

Private Sub btnsave_Click()

Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng1 As Range, rng2 As Range

Set ws1 = ThisWorkbook.Sheets("main")
Set ws2 = ThisWorkbook.Sheets("Sor4main")
Set rng1 = Application.WorksheetFunction.XLookup(ws1.Range("E2"), ws1.Range("B:B"), ws1.Range("B:B").Offset(0, 1), "", 0, 1)
Set rng2 = ws2.Range("A3:CB3")
    
    ws1.Activate
    rng1.Activate
    ActiveCell.Select

    rng2.Copy
    rng1.PasteSpecial xlPasteValues

Set ws1 = Nothing
Set ws2 = Nothing
Set rng1 = Nothing
Set rng2 = Nothing

Application.CutCopyMode = False
ThisWorkbook.Save
    
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
ahmad
  • 21
  • 6
  • By chance I found a solution to the problem at the end of the code . i add application.visible = true application.visible = false that's it .. I think the program needed to be vented some how to release the ram memory .. – ahmad Jan 09 '23 at 02:00
  • Welcome ahmad! Please take some time to read the introduction to Stack Overflow and earn your next badge. https://stackoverflow.com/tour – user10186832 Jan 09 '23 at 03:44
  • The ranges you are using are huge. column B:B is 1048576 long – user10186832 Jan 09 '23 at 03:45
  • I recommend reading [How to avoid using select](https://stackoverflow.com/a/23913882/16578424) and [How to avoid copy/paste](https://stackoverflow.com/a/64611707/16578424) - if you apply those adivses, the performance will heavily increase – Ike Jan 09 '23 at 06:47
  • I'm working on a potato and I couldn't replicate the issue even after trying to make it preform the calculation 30 times in a row. – Cameron Critchlow Jan 09 '23 at 19:51

0 Answers0