For time calculation in macro




Dim shtcount, mshtcount, i, counter As Integer
'for timer
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
  StartTime = Timer

'code 

SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation

-----
'1) to add all excels to summary workbook which contains yes in summary sheet
Sub DoThis()
    Dim shSummary As Worksheet
        Dim c As Range, wbk As Workbook
        Set shSummary = Sheets("Summary")
        With Summary
        For Each c In shSummary.Range("B1:" & shSummary.Range("B1").End(xlDown).Address)
            If UCase(c.Value) = UCase("YES") Then
                If dir("\\s\d\Desktop\ALL indexs\" & c.Previous & ".xlsx") <> "" Then
                    Sheets.Add after:=Sheets(Sheets.count)
                    ActiveSheet.Name = c.Previous
                    Range("E1") = "Difference"
                    Set wbk = Workbooks.Open("\\dg\g\Desktop\ALL indexs\" & c.Previous & ".xlsx")
                    wbk.Sheets(1).UsedRange.Copy ThisWorkbook.ActiveSheet.Range("A1")
                    wbk.Close False
                    Range("E2").Formula = "=c2-d2"
                    Range("E2").AutoFill Range("E2:E" & Range("D1").End(xlDown).Row)
                    Range("E:E").Copy
                    Range("E:E").PasteSpecial xlPasteValues
                    Application.CutCopyMode = False
                    'todo
                    Range("c:e").Select
                    Selection.NumberFormat = "0.00"
                    ActiveSheet.UsedRange.AutoFilter Field:=5, Criteria1:="<=-.02", _
                    Operator:=xlOr, Criteria2:=">=.02"
                    lr = Sheets("remarks").Range("a1").CurrentRegion.Rows.count + 1
                    Sheets(c.Previous.Value).UsedRange.Copy Sheets("Remarks").Range("a" & lr)
                    
                    'Sheets(c.Previous.Value).UsedRange.Copy Sheets("remarks").Range("A" & Sheets("remarks").UsedRange.Rows.count + 1)
                     ActiveSheet.UsedRange.AutoFilter
                End If
            End If
        Next
        End With
        Set shSummary = Nothing
End Sub

Comments

Popular posts from this blog

number format

send Mail by outlook from excel sheet

Find and copy the data