Enhance existing VBA for multiple loops

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - looking for a way to expand my loop to also run off another loop. What I mean is it runs for all Items for each date. Currently I have it loop for all dates as seen below and want to add items. For example:

Dates and Items would like to be amendable based off another range in another sheet.

Date 5/5/21; run for Item A, B, C then
Date 5/6/21: run for Item A, B, C and so forth

VBA Code:
Option Explicit
Sub RUN_DATE_LOOP()
Dim Dates As Date
Dim i As Long

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

Call Clear

Sheets("Sec").Range("Items") = A

' Run Dates loop
i = 1
Do Until Sheets("Date Loop").Range("Dates").Offset(i, 0) = ""
Dates = Sheets("Date Loop").Range("Dates").Offset(i, 0)
Sheets("Sec").Range(REQDATE") = Dates
Call Sec2
i = i + 1
Loop

Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Ok challenge number 1. it is taking almost 1min6sec to run. if i do just the dates my old way but that didn't have the items 3 per. it was 17 seconds x 3 (items). So about 15secs faster.
 
Upvote 0
That is exactly why I suggest using variant arays because it would be even slower ifyou were referencing the worksheet everytime. The code that I have written is very fast , the time must be taken in your sub routine sec2.
Just try it with the call to sec2 commented out and you will see it is lightening fast
 
Upvote 0
in both ways i need sec2. that is a VBA that has to be run in both scenarios. I would expect i wouldnt be going slower in your approach
 
Upvote 0
If you want to speed it up , you could pass the "View" and the "Date" as parameters to the Sec2 subroutine, but that depends on whether there are any equations on the Sec workhseet that use the "REQDate" or S_Items .
Also if it takes 17 secs to run with a single loop I suspect it will be possioble to speed up the Sec2 routine. Can you post the code of Sec2?
 
Upvote 0
sec2 is locked for viewing I cannot. but if both use it should be a non issue when it comes to timing.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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