vba for vlookup to paste info onto next line down in next open cell in new workbook

Saoirse

New Member
Joined
Jan 27, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Trying to copy with a vlookup info from the list from workbook "Shrinkage" sheet "Friday" then paste it onto workbook "Productivity tracker" sheet "Allie" on the next row down in columns Y:AD.

here afre the macros i keep trying but neither one seems to pull the info the paste onto the "Allie" spreadsheet on the next line down starting on column Y.
Sub shrinkpull()

Dim NextRow As Integer

NextRow = sheets("Allie").Cells(Rows.Count, 23).End(xlUp).Row + 1

sheets("Allie").Range("Y" & NextRow) = Workbooks("Shrinkage.xlsx").Worksheets("Monday").Range("C4:H4").copy _
("Productivity Tracker.xlsm").Worksheets("Allie").Range("Y & NextRow")

End Sub
Sub vlook()
'
Dim NextRow As Integer

NextRow = sheets("Allie").Cells(Rows.Count, 23).End(xlUp).Row + 1
'
Sheets("Allie").Range("Y" & NextRow)= WorksheetFunction.VLOOKUP([Shrinkage.xlsm](sheets("Friday").Range ("A4"),[Shrinkage.xlsm]sheets("Friday").Range("A3:H32"), 3,FALSE))


End Sub


Shrinkage.xlsm
ACDEFGH
1Enter the minutes worked for each category. EX: 1 hour = 60; 2 hours = 120ComplianceSystem issuesFrontierLetters / Special projects Call pulls, fee calculations, large casesbuzz, trianing, coaching
2
3Alexis
4Allie 601080452030
5Aaron
6 Breonna
Friday


Productivity Tracker.xlsm
ABCDIJMNSTUVWXYZAAABACAD
2DateAdjustments madePrep Cases WorkedTimeDenial ClosuresTimeACETimeApproved ClosureTimeWorldpay SettlementsTimeTotal Minutes Worked % time working casesComplianceSystem issuesFrontierLetters / Special ProjectsCall pulls / fee calculations / large casesbuzz, trianing, coaching
32/1/2022462721617 0114472128864%601080452030
42/2/202236118853551528133918541%
52/3/2022482161611213176892722647%
62/6/202218216321 01040398618%
Allie
Cell Formulas
RangeFormula
W3:W6W3=SUM(D3+J3+N3+T3+V3)
X3:X4X3=W3/450
Y3Y3=VLOOKUP('Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!$A$4,'Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!A$3:H$32,3,FALSE)
Z3Z3=VLOOKUP('Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!$A$4,'Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!A$2:H$32,4,FALSE)
AA3AA3=VLOOKUP('Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!$A$4,'Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!A$3:H$32,5,FALSE)
AB3AB3=VLOOKUP('Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!$A$4,'Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!A$3:H$32,6,FALSE)
AC3AC3=VLOOKUP('Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!$A$4,'Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!A$3:H$32,7,FALSE)
AD3AD3=VLOOKUP('Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!$A$4,'Z:\Departmental Shares\dOps\POC Training Material\Intake\Lesli Johnson\[Shrinkage.xlsm]Friday'!A$3:H$32,8,FALSE)
X5:X6X5=W5/480
I3:I6,S3:S6I3=SUM(E3:H3)
M3:M6M3=SUM(K3:L3)
 
I doesn't make sense to just take the next line down based on column Y since the data you are putting in Y has to line up with the date in column A.
What if the next date on a sheet is not the day you are trying to pick up the Shrinkage data for ?
How about having an input box that prompts for the date OR have cell on the spreadsheet that tells it which date you want to process ?
You could use a drop down box for day Monday, Tuesday etc but then we would need a cell to contain a week start or end date.

The next time you post can you put in what time it is at your end or tell me what time zone you are in ?
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Ohh ok, I think I understand what you mean. It definitely would make sense to have the shrinkage info match up with the date from the productivity tracker to verify the date the info goes in on. I just planned on keeping track, but your idea would actually make it even easier! I am so unfamiliar with the abilities of vba and macros and formulas. I really do appreciate all the time and work you are putting in to assist me with this. I hope I am not being overly difficult.

I could easily just put a date in a cell on the Shrinkage sheet to have it match up to the date on the productivity tracker.

I am in the Eastern Standard Time zone.

so i can add the dates in column B or I could I just name the sheets the date? Would that make it easier?
So instead of the sheeting being named "Monday" "Tuesday" ect, they could be "2.14.22" "2.15.22" or would that screw too much up? I am only trying to make it easier to see if this process is possible.


Copy of send to self.xlsx
ABCDEFGHI
1Enter the minutes worked for each category. EX: 1 hour = 60; 2 hours = 1202/14/2022ComplianceSystem issuesFrontierLetters / Special projects Call pulls, fee calculations, large casesBuzz, trianing, coaching Approved by: (input which leader approved)
2
3Alexis
4Allie601080452030
5Aaron668
6Breonna30152530
7Brittany
8Carl
9Cindy
10Courtney1201012010
Sheet1
 
Upvote 0
Also, when I replace with the new code, I got this error:

1644873478781.png


1644873520213.png
 
Upvote 0
Can we start with getting the code to run and see what you think.
I don't know what happened but the code seems to have lost the closing bracket ")" on the yellow highlighted line.
Can you add that to it and run it again ?
 
Upvote 0
Sub CopyShrinkage()

' Lookups are based on Individual's names in the sheetname
' Date using Day of Week as Shrinkage Sheet name

Dim wbProd As Workbook, wbShrink As Workbook
Dim shtProd As Worksheet, shtShkDay As Worksheet
Dim prdFirstRow As Long, prdLastRow As Long
Dim shkFirstRow As Long, shkLastRow As Long
Dim dtCell As Range, dtCellDay As String
Dim persName As String, shkPersRow As Variant
Dim rngShkName As Range, rngShkPers As Range

Set wbProd = ThisWorkbook
Set wbShrink = Workbooks("Shrinkage.xlsm")

prdFirstRow = 3
shkFirstRow = 3

For Each shtProd In wbProd.Worksheets
' Test for Names of sheets in Productivity Tracker that are not names of people and need to be excluded
If shtProd.Name <> "Adjustments" And _
shtProd.Name <> "Compilation" And _
shtProd.Name <> "timing" Then
prdLastRow = shtProd.Range("A" & Rows.Count).End(xlUp).Row
' Get Person name from sheet name
persName = shtProd.Name

For Each dtCell In wbShrink.Range("A" & shkFirstRow & ":A" & shkLastRow)
dtCellDay = Format(dtCell, "dddd")
On Error Resume Next
Set shtShkDay = wbShrink.Worksheets(dtCellDay)
If Err Then
MsgBox "Prod Sheet: " & vbTab & shtProd.Name & vbLf & _
"Cell: " & vbTab & vbTab & dtCell.Address & vbLf & _
"Cell Value: " & vbTab & dtCell & vbLf & _
"WeekDay Sheet: " & vbTab & dtCellDay
Exit Sub
End If
On Error GoTo 0
shkLastRow = shtShkDay.Range("A" & Rows.Count).End(xlUp).Row
Set rngShkName = shtShkDay.Range("A1" & ":A" & shkLastRow)

If Not IsError(Application.Match(persName, rngShkName, 0)) Then
shkPersRow = Application.Match(persName, rngShkName, 0)

Set rngShkPers = shtShkDay.Range("C" & shkPersRow & ":H" & shkPersRow)
shtProd.Range("Y" & dtCell.Row).Resize(, rngShkPers.Columns.Count).Value = rngShkPers.Value

End If

Next dtCell
End If

Next shtProd

End Sub


Same error, same line. The closing bracket is still there. I double checked that as well.

I'm sending images of the actual charts and maybe that could help if you actually saw them with the tabs? Not sure. I am willing to try anything.

This is the Productivity tracker
1644940557128.png

This is the productivity tracker continued, to the right side of the screen, since the first image got cut off.
1644940469643.png


This part is the shrinkage sheet.
1644940419662.png

I don't know if seeing the charts will help. But it is worth a shot. I have been researching how to update the code, but my beginner status is definitely not helping.

Again, thank you for not giving up on me so far. I really appreciate everything you are doing to help me.
 
Upvote 0
The line it is erroring out on is not the original line in the code that I gave you. Please change it back to:
VBA Code:
                For Each dtCell In shtProd.Range("A" & prdFirstRow & ":A" & prdLastRow)
and then let me know how you go.
 
Upvote 0
Is there any reason you have merged rows 1 & 2 on your shrinkage worksheet ? Merging cells is almost always a really bad idea and merging rows 1 and 2 doesn't seem to serve any purpose.
Also I was working on the assumption that the productivity tracker was just 1 week's worth of data, it looks like it is a running list for a calendar month, is that correct ?
 
Upvote 0
OK, I ran it with that line corrected and got this:
1645024311451.png


I was asking myself the same question the other day, why those are merged. I Now unmerged them. So row 2 is the first employee name.

To answer your second question, the Productivity tracker is not set up for a specific timeframe. Everyday it adds one more row of data, on and on forever. I just created it and started adding data on Feb 1st. That is why it appears that way.
 
Upvote 0
Thanks for that.
Try the below:-
  • It will ask you to enter the date you want to copy in from the Shrinkage sheet.
  • It will convert that date to the Day of the week and go looking for that sheet.
  • It currently assumes that you have the date in B1 in each Shrinkage sheet to make sure you have the right week's Shrinkage sheet.
    You can remove this check if you don't want to put a date in B1
  • It will look through each productivity tracker sheet that is not excluded and find that date and bring in the shrinkage data
Let me know how you go.

VBA Code:
Sub CopyShrinkage_process_InputDate()

    ' Lookups are based on Individual's names in the sheetname
    ' Date using Day of Week as Shrinkage Sheet name
    
    Dim wbProd As Workbook, wbShrink As Workbook
    Dim shtProd As Worksheet, shtShkDay As Worksheet
    Dim prdFirstRow As Long, prdLastRow As Long
    Dim shkFirstRow As Long, shkLastRow As Long
    Dim dtCell As Range                         ' XXX Should not be required
    Dim strCellDay As String
    Dim persName As String, shkPersRow As Variant
    Dim rngShkName As Range, rngShkPers As Range

    Set wbProd = ThisWorkbook
    Set wbShrink = Workbooks("Shrinkage.xlsm")
    
    prdFirstRow = 3
    shkFirstRow = 3
    
    ' Input Date to process
    Dim strInput As String
    Dim dtInput As Date
    Dim prdRowNo As Long
    
    strInput = Application.InputBox(prompt:="Enter Date to Process: ", Default:=FormatDateTime(Date, vbShortDate), Type:=2)
    If Not IsDate(strInput) Then
        MsgBox "Not a valid date, please try again"
        Exit Sub
    End If
    
    dtInput = CDate(strInput)
    strCellDay = Format(dtInput, "dddd")
        
    On Error Resume Next
        Set shtShkDay = wbShrink.Worksheets(strCellDay)
        If Err Then
            MsgBox "The Shrinkage Workbook does not have a sheet " & vbLf & _
                   "For: " & vbTab & strCellDay
            Exit Sub
        End If
    On Error GoTo 0
    
    '------ Checks Shrinkage sheet cell B1 to see if it is the same date -----
    ' remove this if the Shrinkage sheet doesn't contain dates in B1
    If CLng(dtInput) <> CLng(shtShkDay.Range("B1").Value) Then
        MsgBox "Date Entered is in a different week to Shrinkage workbook" & vbLf _
                & "Input Date was: " & vbTab & FormatDateTime(dtInput, vbShortDate) & vbLf _
                & "This is: " & vbTab & vbTab & strCellDay & vbLf _
                & "Which is dated: " & vbTab & FormatDateTime(shtShkDay.Range("B1").Value, vbShortDate)
        Exit Sub
    End If
    '--------------------------------------------------------------------------
    shkLastRow = shtShkDay.Range("A" & Rows.Count).End(xlUp).Row
    Set rngShkName = shtShkDay.Range("A1" & ":A" & shkLastRow)
        
    For Each shtProd In wbProd.Worksheets
        ' Test for Names of sheets in Productivity Tracker that are not names of people and need to be excluded
        If shtProd.Name <> "Adjustments" And _
            shtProd.Name <> "Compilation" And _
            shtProd.Name <> "timing" Then
                prdLastRow = shtProd.Range("A" & Rows.Count).End(xlUp).Row
                ' Get Person name from sheet name
                persName = shtProd.Name
                
                ' Find Input Date in Person's sheet
                With Application
                    prdRowNo = .IfError(.Match(CLng(dtInput), shtProd.Columns(1), 0), 0)
                End With
                
                ' Find Person's Name in Shrinkage sheet for the day of the week matching the input date
                If Not IsError(Application.Match(persName, rngShkName, 0)) Then
                    shkPersRow = Application.Match(persName, rngShkName, 0)
                    
                        Set rngShkPers = shtShkDay.Range("C" & shkPersRow & ":H" & shkPersRow)
                        shtProd.Range("Y" & prdRowNo).Resize(, rngShkPers.Columns.Count).Value = rngShkPers.Value
                Else
                        ' Remove this if it is a common occurence for people not being on the Shrinkage sheet
                        MsgBox persName & " Not found on " & strCellDay
                End If
                
        End If
    
    Next shtProd

End Sub
 
Upvote 0
Solution
Holy Crapola!!! It Works!! Oh MY Goodness, This is amazing! I don't know how you did it, but you did!!! Thank you SOOO MUCH!

I do get these errors when I run it though.

1645127774667.png

1645127822719.png


Not sure if it is because I don't have EVERY employee tab filled in on the productivity tracker or not. But that could be it.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top