RockandGrohl
Well-known Member
- Joined
- Aug 1, 2018
- Messages
- 801
- Office Version
- 365
- Platform
- Windows
My predecessor wrote a lot of VBA code for a lot of programs, and these were written across the years where his capabilities evolved and you can see various levels of sophistication as you look through his old sheets.
Something he's relied on time and time again is a Do Until loop where each cell in a list, 10's, 100's or 1000's and even 10,000's long is checked for some logic.
An example would be a simple thing like:
Now when it finds the cell it wants, the code progresses onwards and various variables are set.
Now obviously Excel spits through these in milliseconds, but is there a faster way?
My project is to reduce the amount of time a userform takes to open, we're talking 12-20 seconds each time. I have some ideas to improve efficiency but I was wondering if a Do Until loop can be replaced wholesale with a find?
Could I for instance say Find where [Criteria 1], [Criteria 2] is applicable instead of checking every line?
So in another example, I could want to find where a newspaper name AND a Template size match what I have held in memory, "Swindon Standard" and "16x10"
I would want to find where "Swindon Standard" sits in column A AND where "16x10" also sits on column C.
Cheers.
Something he's relied on time and time again is a Do Until loop where each cell in a list, 10's, 100's or 1000's and even 10,000's long is checked for some logic.
An example would be a simple thing like:
Code:
Do Until Cells(ActiveCell.Row, "C").Value = "" If Cells(ActiveCell.Row, "E").Value = AdSelect.PapNam Then
Exit Do
End If
ActiveCell.Offset(1, 0).Activate
Loop
Now when it finds the cell it wants, the code progresses onwards and various variables are set.
Now obviously Excel spits through these in milliseconds, but is there a faster way?
My project is to reduce the amount of time a userform takes to open, we're talking 12-20 seconds each time. I have some ideas to improve efficiency but I was wondering if a Do Until loop can be replaced wholesale with a find?
Could I for instance say Find where [Criteria 1], [Criteria 2] is applicable instead of checking every line?
So in another example, I could want to find where a newspaper name AND a Template size match what I have held in memory, "Swindon Standard" and "16x10"
I would want to find where "Swindon Standard" sits in column A AND where "16x10" also sits on column C.
Cheers.