Avoid Memory Issue When running this macro?

squeakums

Well-known Member
Joined
May 15, 2007
Messages
823
Office Version
  1. 365
I'm running the below macro several times in a combined macro sheet - this moves columns once the data is imported. Is there a way to avoid getting that annoying memory error with massive macros or to rewrite the below? It works on other tabs but is erroring out on this one.


Dim arrColOrder As Variant, ndx As Integer
Dim Found As Range, counter As Integer

'Place the column headers in the end result order you want.
arrColOrder = Array("LOB Vendor Executive", "Vendor Manager", "Vendor Name", "Finding ID", "Risk Level", "Due Date", "Finding Status", "Question", "Region")



counter = 1

Application.ScreenUpdating = False



For ndx = LBound(arrColOrder) To UBound(arrColOrder)

Set Found = Rows("1:1").Find(arrColOrder(ndx), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)

If Not Found Is Nothing Then
If Found.Column <> counter Then
Found.EntireColumn.Cut
Columns(counter).Insert Shift:=xlToRight
Application.CutCopyMode = False
End If
counter = counter + 1
End If

Next ndx
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Instead of cutting/inserting entire columns you could try only cutting/inserting rows with data.

Alternatively, and this might not be suitable, you could copy the columns, in the required order, to a new sheet.

That would avoid shifting large amounts of data around as you cut/insert.
 
Upvote 0
How would I write the macro only cut rows with data in it verses a2:a3000 etc?
 
Upvote 0
I found another way - if you just save the file while in the macro it'll wipe the memory and start a fresh and then it won't cause the issues.
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,365
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top