ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 843
- Office Version
- 365
- 2019
- Platform
- Windows
I need some help creating a line of code that will help me optimize my current VBA. I am running into performance issues because of running my loop off of each individual range but I can improve it by combining ranges. I have to apply each due to the size of my data. I have since improved it but need help to further optimize. Below is my dilemma and what I would need.
I can extract from my core system by identifier to limit the data by doing so I still reach my excel row limit. So I loop through using a named range (column B below), to avoid that and transfer just the data I need over, clearing and starting over. I can combine those ranges using variables and looking for a way to do that dynamically. A way to run as many combined without reaching my excel row limit. In my prep work I can get how many rows each range would generate (column C below). In this example I could run the first 12. Then the last 2. So I could cut my loop from 14 to 2. The NEW ranges would need to combine the records separated by a colon like this:
Loop 1 - G########:H########:M########:N########:0########:1########:2########:3########:4########:5########:6########:7########
Loop 2 - 8########:9########
WsSec where I extract from system
WsCus (sheet)
I can extract from my core system by identifier to limit the data by doing so I still reach my excel row limit. So I loop through using a named range (column B below), to avoid that and transfer just the data I need over, clearing and starting over. I can combine those ranges using variables and looking for a way to do that dynamically. A way to run as many combined without reaching my excel row limit. In my prep work I can get how many rows each range would generate (column C below). In this example I could run the first 12. Then the last 2. So I could cut my loop from 14 to 2. The NEW ranges would need to combine the records separated by a colon like this:
Loop 1 - G########:H########:M########:N########:0########:1########:2########:3########:4########:5########:6########:7########
Loop 2 - 8########:9########
WsSec where I extract from system
WsCus (sheet)
Book1 | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | G | G######## | 3696 | 1374956 | ||
2 | H | H######## | 135 | |||
3 | M | M######## | 380 | |||
4 | N | N######## | 370 | |||
5 | 0 | 0######## | 259320 | |||
6 | 1 | 1######## | 186070 | |||
7 | 2 | 2######## | 21008 | |||
8 | 3 | 3######## | 16295 | |||
9 | 4 | 4######## | 21225 | |||
10 | 5 | 5######## | 210450 | |||
11 | 6 | 6######## | 18517 | |||
12 | 7 | 7######## | 241000 | |||
13 | 8 | 8######## | 256900 | |||
14 | 9 | 9######## | 139590 | |||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D1 | D1 | =SUM(C1:C14) |
VBA Code:
'check if row limit will be exceeded if so then proceed with running per starting value of indentifier transfering to sheet
If TOTAL > 1048576 Then
'set for lot runs and clear then run it
With WsSec
.Range("ITEM") = "I"
.Range("OP") = "="
End With
t = Timer
' Run loop for range, clear, run, copy and paste into its respective sheet
i = 0
Do Until WsCus.Range("FILTER").Offset(i, 0) = ""
FILTER = WsCus.Range("FILTER").Offset(i, 0)
'apply filter to start loop and activate sheet
With WsSec
.Range("VALUE") = FILTER
.Application.Calculation = xlManual
.Range("A10").CurrentRegion.Delete
.Activate
End With
Debug.Print "Worksheets(WsSec)Delete... :" & Format(Timer - t, "0.00") & " seconds"
t = Timer
Call Sec2
Debug.Print "Worksheets(WsSec)... :" & Format(Timer - t, "0.00") & " seconds"
'Other code to transfer data, apply formulas, and etc...
Last edited: