srikanth sare
New Member
- Joined
- May 1, 2020
- Messages
- 30
- Office Version
- 2013
- Platform
- Windows
- MacOS
- Mobile
- Web
Hi
The macro is working fine but it takes more time to run the code
help me in solving the issue
The macro is working fine but it takes more time to run the code
help me in solving the issue
VBA Code:
Private Sub ASALES()
On Error GoTo EH
Application.Run "TurnOff"
Sheet5.Unprotect "1818"
Sheet5.Cells.Copy
Sheet8.[a1].PasteSpecial 13
Application.CutCopyMode = False
Sheet9.Range("A6:EB9999").Clear
Dim xRg As Range
Dim lastrow As Variant
Dim I, J As Long
I = Sheet8.UsedRange.Rows.Count
J = 6
Set xRg = Union(Sheet8.Range("BW6:BW" & I), Sheet8.Range("BY6:BY" & I), Sheet8.Range("CA6:CA" & I), Sheet8.Range("CC6:CC" & I), Sheet8.Range("CE6:CE" & I), Sheet8.Range("CG6:CG" & I), _
Sheet8.Range("CI6:CI" & I), Sheet8.Range("CK6:CK" & I), Sheet8.Range("CM6:CM" & I), Sheet8.Range("CO6:CO" & I), Sheet8.Range("CQ6:CQ" & I), Sheet8.Range("CS6:CS" & I), _
Sheet8.Range("CU6:CU" & I), Sheet8.Range("CW6:CW" & I), Sheet8.Range("CY6:CY" & I), Sheet8.Range("DA6:DA" & I))
For Each KCELL In xRg
If KCELL.Value = Sheet5.Range("K1").Value Then
KCELL.EntireRow.Copy
Sheet9.Range("A" & J).PasteSpecial xlPasteValues
Sheet9.Range("A" & J).PasteSpecial xlPasteFormats
J = J + 1
End If
Next
With Sheet9
lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set rng = .Range("A5:EB" & lastrow)
rng.RemoveDuplicates Columns:=3, Header:=xlYes
rng.Sort key1:=Sheet9.Range("C5"), order1:=xlAscending, Header:=xlYes
End With
Sheet8.Cells.Clear
CleanUp: On Error Resume Next
Application.Run "TurnOn"
Sheet5.Protect "1818", DrawingObjects:=False, Contents:=True, Scenarios:=False, UserInterFaceOnly:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowSorting:=True, AllowFiltering:=True
Exit Sub
EH: Debug.Print Err.Description ' Do error handling
MsgBox "Sorry, an error occured." & vbCrLf & Err.Description, vbCritical, "Error!"
Resume CleanUp
End Sub