Linking workbook data, but searching to find the data? Google Sheets

TAPS_MikeDion

Well-known Member
Joined
Aug 14, 2009
Messages
622
Office Version
  1. 2011
Platform
  1. MacOS
Hey all,

I'm assuming there's a way to do this, but I'm not sure how to go about it. Any help would be greatly appreciated. My guess is that this would be a VBA project and I'm fine with that.

I have two (2) workbooks. One named "Missed Work" and the other "Payroll Totals."

The columns in the workbooks are as follows:
"Missed Work"
A = Last Name of the employee who missed work
B = First Name of the employee who missed work
E = Location the work was missed. If the word COVID is in the cell, then it was a COVID job, otherwise it was a Regular job
F = # of hours covered
G = Last Name of the employee who covered the work
H = First Name of the employee who covered the work

"Payroll Totals"
B = Last Names of the employees
C = First Names of the employees
I = COVID Cover Hours
J = Regular Cover Hours

What I'm trying to do is have the Payroll Totals auto-fill columns I and/or J with the number of hours from the Missed Work sheet that were covered by another employee.


For example:
Data in the Missed Work sheet

A
B
E
F
G
H
LAST NAME
FIRST NAME
LOCATION
HOURS
COVERED BY (LAST NAME)
COVERED BY (FIRST NAME)
DoeJaneLocation A - COVID5.00SmithJim
RiveraCarlosLocation D3.00JonesMary



Data in the Payroll Totals sheet:

B
C
I
J
LAST NAME
FIRST NAME
COVID COVER HOURS
REGULAR COVER HOURS
BarnesCindy
JonesMary3.00
MoraPablo
SmithJim5.00



Please and thank you to anyone able to assist on this!
-Mike
 
Last edited by a moderator:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You might consider the following...

VBA Code:
Sub PayrollTotals()
Dim wb1 As Workbook, wb2 As Workbook
Dim arr1 As Variant, arr2 As Variant
Dim i As Long, j As Long, k As Long

Set wb1 = Workbooks("Payroll Totals.xlsm")
Set wb2 = Workbooks("Missed Work.xlsm")
arr1 = wb1.Sheets("Payroll Totals").UsedRange
arr2 = wb2.Sheets("Missed Work").UsedRange

For i = 2 To UBound(arr2)
    For j = 2 To UBound(arr1)
        If arr2(i, 7) & arr2(i, 8) = arr1(j, 2) & arr1(j, 3) Then
            If InStr(1, arr2(i, 5), "COVID", vbTextCompare) Then
                arr1(j, 9) = arr2(i, 6)
            Else
                arr1(j, 10) = arr2(i, 6)
            End If
        End If
    Next j
Next i
wb1.Sheets("Payroll Totals").UsedRange = arr1
End Sub

Please note that both workbooks need to be open when running the code.

Cheers,

Tony

p.s. Just noted you're on a MacOS... so the above code may or may not work as it's written for a pc.
 
Upvote 0
Hi Tony,

Ugh. I never tried using VBA in Google Sheets and now I see that it isn't an option so I can't use your code. With what I'm doing I have to use Google Sheets, not Excel. Again, I didn't know you couldn't use VBA in Google Sheets or I wouldn't even have posted the question. I'm sorry you did all that work for nothing. :(

Thank you very much for trying to help though.
 
Upvote 0
Hi Tony,

Ugh. I never tried using VBA in Google Sheets and now I see that it isn't an option so I can't use your code. With what I'm doing I have to use Google Sheets, not Excel. Again, I didn't know you couldn't use VBA in Google Sheets or I wouldn't even have posted the question. I'm sorry you did all that work for nothing. :(

Thank you very much for trying to help though.
" I'm sorry you did all that work for nothing." No worries, Mike. Sorry it didn't work out. Good luck finding a solution.
 
Upvote 0
I'm probably making this sound far easier than it may be since I am not that well versed with formulas, but is a formula possible here?

If I were to use the IMPORTRANGE formula in the Payroll Totals sheet to copy the data from columns E - H of the Missed Work sheet, would a formula be able to make the name and location comparisons, and if a match is found, place the data into the matching cells of the Payroll Totals sheet?

Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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