I have two tabs in an excel file. I've defined them as shop (the shop doing the work) and jon (job order number). "Shop" shows the money that each shop has spent against each job order number. "Jon" shows the total bugetted for each job order number. I want the macro to go down the list of job order numbers on "jon" (jon column B) and check "shop"s job order numbers (shop column B) for the totals spent per shop (shop column J), and input the total spent per job order number in jon column E.
A complication is that shop column J, the totals spent per shop for a job order number, is a calculation - not just a value.
Here is my code. It's filling in the right column in the jon tab, but it's only giving me 0 for all of the values. Any idea what I'm doing wrong?
A complication is that shop column J, the totals spent per shop for a job order number, is a calculation - not just a value.
Here is my code. It's filling in the right column in the jon tab, but it's only giving me 0 for all of the values. Any idea what I'm doing wrong?
Sub total_spent_jon()
'The purpose of this Macro is to sum the amont spent per shop for a JON on DWU_Shop
'and list that sum on DWU_Jon_Balance, and then calculate the Remaining.
Dim shop As Worksheet 'This is the worksheet that lists totals spent per shop
Set shop = Sheets("DWU_Shop")
Dim jon As Worksheet 'This is the worksheet that lists the total budgetted per Jon
Set jon = Sheets("DWU_JON_Balance")
Dim sRow As Long 'row index on shop worksheet
Dim jRow As Long 'row index on jon worksheet
Dim sCount As Long
sCount = 0
Dim jCount As Long
jCount = 0
Dim spent As Long 'this is the "shoebox" where we'll be storing and calculating the spent # per Jon
Sheets("DWU_JON_Balance").Activate 'This section of code clears the previous Spent values and color coding
Range("E2:E300").Select
Selection.Interior.ColorIndex = 0
Selection.ClearContents
spent = 0
For jRow = 2 To jon.Range("A65536").End(xlUp).Row
For sRow = 2 To shop.Range("A65536").End(xlUp).Row
If shop.Cells(sRow, "B") = jon.Cells(jRow, "B").Value Then
sCount = sCount + 1
If shop.Cells(sRow, "P").Value = 1 Then 'Evaluate if JON matches
spent = spent + shop.Cells(sRow, "I").Value 'Add to spent shoebox
End If
jon.Cells(jRow, "E").Value = spent 'paste total spent into jon worksheet
jCount = jCount + 1 'This checks the next line of the jon worksheet
End If
Next sRow
Next jRow
End Sub