Hi Everyone,
Looking for some help.
I have written a macro which basically collates data from 3 different files, pastes into different sheets of my master file (Admin Console) and then create a single dashboard with all data into single file (Dashboard).
I also wanted to ensure that I don't overwrite old data in Dashboard sheet, and hence written a subcode to do the INSERT only if the rows is not pre existing.
Now my challenge is that the code is too slow while I am using hardly 2500 rows of total data. Can you guys help me optimize this code so that it works cleaner and faster.
-------------------------------------------------
>>> use code - tags <<<
------
Looking for some help.
I have written a macro which basically collates data from 3 different files, pastes into different sheets of my master file (Admin Console) and then create a single dashboard with all data into single file (Dashboard).
I also wanted to ensure that I don't overwrite old data in Dashboard sheet, and hence written a subcode to do the INSERT only if the rows is not pre existing.
Now my challenge is that the code is too slow while I am using hardly 2500 rows of total data. Can you guys help me optimize this code so that it works cleaner and faster.
-------------------------------------------------
>>> use code - tags <<<
Code:
Sub RowCounter()
Dim Rcntr1 As Integer
Dim Rcntr2 As Integer
Dim Rcntr3 As Integer
Dim RcntrM As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim Dup As Integer
Dim Duplicate As Integer
With Workbooks("Admin Console-WIP.xlsm").Sheets("Simran")
Rcntr1 = .Range("E2", .Range("E" & .Rows.Count).End(xlUp)).Rows.Count
End With
With Workbooks("Admin Console-WIP.xlsm").Sheets("Sravanthi")
Rcntr2 = .Range("E2", .Range("E" & .Rows.Count).End(xlUp)).Rows.Count
End With
With Workbooks("Admin Console-WIP.xlsm").Sheets("Deepanshi")
Rcntr3 = .Range("E2", .Range("E" & .Rows.Count).End(xlUp)).Rows.Count
End With
With Workbooks("Admin Console-WIP.xlsm").Sheets("Dashboard")
RcntrM = .Range("E2", .Range("E" & .Rows.Count).End(xlUp)).Rows.Count
End With
MsgBox ("no. of Rows are" & Rcntr1 & "," & Rcntr2 & "," & Rcntr3 & "," & RcntrM)
Wcntr = RcntrM + 1
Duplicate = 0
'Copying data from Sravanthi Sheet
For i = 2 To Rcntr2
Dup = 0
With Workbooks("Admin Console-WIP.xlsm").Sheets("Sravanthi")
For j = 2 To RcntrM
If (Worksheets("Sravanthi").Range("G" & i).Value = Worksheets("Dashboard").Range("M" & j).Value) Then
Dup = Dup + 1
End If
Next j
If Dup = 0 Then
For k = 0 To 19
Worksheets("Sravanthi").Range("A" & i).Offset(0, k).Copy Worksheets("Dashboard").Range("G" & Wcntr).Offset(0, k)
Next k
Wcntr = Wcntr + 1
End If
End With
Next i
'Copying data from Simran Sheet
For i = 2 To Rcntr1
Dup = 0
l = 0
With Workbooks("Admin Console-WIP.xlsm").Sheets("Simran")
For j = 2 To RcntrM
If (Worksheets("Simran").Range("G" & i).Value = Worksheets("Dashboard").Range("M" & j).Value) Then
Dup = Dup + 1
End If
Next j
If Dup = 0 Then
For k = 0 To 20
Worksheets("Simran").Range("A" & i).Offset(0, k).Copy Worksheets("Dashboard").Range("G" & Wcntr).Offset(0, k)
Next k
Wcntr = Wcntr + 1
End If
End With
Next i
'Copying data from Deepanshi Sheet
For i = 2 To Rcntr3
Dup = 0
l = 0
With Workbooks("Admin Console-WIP.xlsm").Sheets("Deepanshi")
For j = 2 To RcntrM
If (Worksheets("Deepanshi").Range("G" & i).Value = Worksheets("Dashboard").Range("M" & j).Value) Then
Dup = Dup + 1
End If
Next j
If Dup = 0 Then
For k = 0 To 20
Worksheets("Deepanshi").Range("A" & i).Offset(0, k).Copy Worksheets("Dashboard").Range("G" & Wcntr).Offset(0, k)
Next k
Wcntr = Wcntr + 1
End If
End With
Next i
MsgBox ("Operations Complete")
End Sub