Ok I have some code which looks up a value in row 1 of sheet1 in a sheet specified by column A.
It then returns the value in the column before where the value is found.
However I am having a problem that there can be more than 1 instance of the value on the sheet (sheetP).
In this instance I would like to return the sum of the values, any help would be greatly appreciated.
Here is my code
It then returns the value in the column before where the value is found.
However I am having a problem that there can be more than 1 instance of the value on the sheet (sheetP).
In this instance I would like to return the sum of the values, any help would be greatly appreciated.
Here is my code
Code:
Sub GetValues()
Dim P As String, _
ws1 As Worksheet, _
ws2 As Worksheet, _
Y As String, _
X As String, _
rng As Range
Set ws1 = Sheets("Sheet1")
lnglastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Y = 2
Do
P = ws1.Range("A" & Y)
Set ws2 = Sheets(P)
X = 2
Do
WeekStart = ws1.Range("A1").Offset(0, X)
With ws2.Range("D:D")
Set rng = .Find(WeekStart, , xlValues)
End With
If Not rng Is Nothing Then
rng1 = rng.Address
ws1.Range("A" & Y).Offset(0, X) = rng.Offset(0, -1)
End If
X = X + 2
Loop Until X > 6
Y = Y + 1
Loop Until Y = lnglastRow + 1
End Sub