Do Until VBA Optimization

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - I am fairly basic on all my VBA, I have yet to find the best way on certain approaches. One approach is below, is there a better, faster, or more efficient way? i want to run my VBA "sec2" for each view on another sheet called views, then loop until it is finished.

VBA Code:
Sub TRAN()
Dim i%
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual

ActiveSheet.AutoFilterMode = False

Sheets("TRANS").Activate
Call Clear
i = 1
With Sheets("Views")
    Do Until .Range("VIEW").Offset(i, 0) = ""
    
    Sheets("TRANS").Range("SP") = .Range("VIEW").Offset(i, 0)
    Call Sec2
    
    i = i + 1
    Loop

End With

If Not ActiveSheet.AutoFilterMode Then ActiveSheet.Range("10:10").AutoFilter

Application.Calculation = xlCalculationAutomatic

With ActiveWindow
    .SplitColumn = 9
    .SplitRow = 10
    .FreezePanes = True
End With

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

End Sub
way to capture the below?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I can think of other ways to do it, but this is probably as efficient as any other. You could change your
VBA Code:
With Sheets("Views")
to
VBA Code:
With Sheets("Views").Range("View")
and then adjust the lines accordingly. That will remove a bit of redundant code - not much admittedly but looking for such is a good habit to get into.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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