marcelita03
New Member
- Joined
- Jan 15, 2013
- Messages
- 38
Hello thanks for stopping to read my post.
Issue:
1- I have a cell ("L1") function that reads the user's laptop ID number in worksheet1
2- I have a macro that looks at that cell ("L1"), and looks that value in 2 places in worksheet2:
a- If the L1 value is found in column D, the entire row is copied to worksheet3
b- If the L1 value is not found in column D, the macro looks in column F
c- If the L1 value is found in column F, the entire row is copied to worksheet3
3. The macro refreshes a Pivot Table out of worksheet1
So in plain words, what my macro does is to recognize who you are (employee ID, column D), and display only the data that belongs to you in a Pivot Table.
Your manager also gets to see it (manager ID, column F) My problem is... the data is huge (60K+ rows) and this method works BUT it takes forever!
I have tried for days to improve my macro... maybe using Autofilter? I just can't figure it out. Any thoughts will be greatly appreciated it
This is my macro today
Issue:
1- I have a cell ("L1") function that reads the user's laptop ID number in worksheet1
2- I have a macro that looks at that cell ("L1"), and looks that value in 2 places in worksheet2:
a- If the L1 value is found in column D, the entire row is copied to worksheet3
b- If the L1 value is not found in column D, the macro looks in column F
c- If the L1 value is found in column F, the entire row is copied to worksheet3
3. The macro refreshes a Pivot Table out of worksheet1
So in plain words, what my macro does is to recognize who you are (employee ID, column D), and display only the data that belongs to you in a Pivot Table.
Your manager also gets to see it (manager ID, column F) My problem is... the data is huge (60K+ rows) and this method works BUT it takes forever!
I have tried for days to improve my macro... maybe using Autofilter? I just can't figure it out. Any thoughts will be greatly appreciated it
This is my macro today
Code:
Sub SlowestMacroEver()
Dim wkbCurrent As Workbook
Dim wksCopySet As Worksheet
Dim wksDataSet As Worksheet
Dim wksUserSet As WorksheetDim strNameMgr As String
Dim strNameEmp As String
Dim strUserName As String
Dim intDataRow As Long
Dim intCopySet As Long
Application.ScreenUpdating = False
Set wkbCurrent = ActiveWorkbook
Set wksDataSet = wkbCurrent.Sheets("worksheet2")
Set wksUserSet = wkbCurrent.Sheets("worksheet1")
Set wksCopySet = wkbCurrent.Sheets("worksheet3")
Unhide '' this is a submacro that unhide all worksheets
DeleteRows ' this is a submacro that deletes all rows in worksheet 3 to clear everything before the macro runs
strUserName = wksUserSet.Cells(1, 12) ' This is "L1"
intDataRow = 2
intCopySet = 2
strNameMgr = wksDataSet.Cells(intDataRow, 4) ' This is column D
strNameEmp = wksDataSet.Cells(intDataRow, 6) ' This is column F
Sheets("worksheet2").Select
Do Until strNameMgr = ""
strNameMgr = wksDataSet.Cells(intDataRow, 4)
strNameEmp = wksDataSet.Cells(intDataRow, 6) ' Here the macro starts looking for the "L1" value in D and F
If strNameEmp = strUserName Or strNameMgr = strUserName Then
wksDataSet.Select
Rows(intDataRow).Select
Selection.Copy
wksCopySet.Select
Rows(intCopySet).Select
Selection.PasteSpecial Paste:=xlPasteValues 'Here the data gets copy/pasted values into worksheet3
intCopySet = intCopySet + 1
End If
intDataRow = intDataRow + 1
Loop
Exit Sub
Application.ScreenUpdating = True
End Sub
Last edited: