Forum Discussion
waygar
Feb 15, 2023Brass Contributor
Speeding Up VBA execution
Hi, The following code searches a large database for cells with a certain fill color and then removes the underlying conditional formatting. The runtime is quite slow. Can this code be made more eff...
HansVogelaar
Jul 26, 2023MVP
Try this version:
Sub Switch()
Dim v As Variant
Dim NRows3 As Long
Dim I As Long
Dim tmp1, tmp2, tmp4
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
NRows3 = 25330
v = Range("E6:I" & NRows3).Value
For I = 1 To UBound(v)
tmp1 = v(I, 1)
v(I, 1) = v(I, 3)
v(I, 3) = tmp1
tmp2 = v(I, 2)
tmp4 = v(I, 4)
v(I, 4) = v(I, 5)
v(I, 2) = tmp4
v(I, 5) = tmp2
Next I
Range("E6:I" & NRows3).Value = v
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Please test on a copy of the worksheet.
waygar
Jul 26, 2023Brass Contributor
Works like a charm - I didnt use a tmp variable thinking the extra step would impose a delay.
However usage of arrays does not keep the formatting , correct?
However usage of arrays does not keep the formatting , correct?
- HansVogelaarAug 22, 2023MVP
Please start a new discussion with that question. I cannot help you with it.
- waygarAug 22, 2023Brass ContributorHi Hans,
Is there a way, using VBA, to change the permissions for defined users such as they can, edit or not, the Allow Edit Ranges set in a Protected Sheet using VBA and not just change the permissions manually each time eg when a user (with limited editing permission) is changed from being just a user to an administrator (with full editing permission)? - HansVogelaarJul 26, 2023MVP
That is correct - keeping the formatting would slow down the code immensely.
The choice is yours...