KlayColgrove
New Member
- Joined
- Oct 19, 2018
- Messages
- 12
I have a piece of code that will find the value I am looking for then post what I need. I am trying to find the next value in the same column that is the same value that I am looking for, but the data that is being inputted will change a little. (I'm only changing "F1" to "G1" everything else will be the same.
Code:
Sub PlaceData()
Dim rng As Range
Dim cl As Range
Dim sFind As String
sFind = Range("C1").Value
Set rng = Range("B5", Range("B65536").End(xlUp))
Set cl = rng.Find(sFind, LookIn:=xlValues)
Const F = "SUMPRODUCT((MONTH(Data!A2:A2000)=" & "F1" & ")*(YEAR(Data!A2:A2000)=2019)*(Data!#2:#2000))"
Dim V, C%
V = [{"S","V","Y","AB","AE","AN","AK","AH"}]
For C = 1 To 8
cl.Offset(, C).Value2 = Evaluate(Replace(F, "#", V(C)))
Next
cl(1, 10).Value2 = Application.Sum(cl(1, 2).Resize(, 8))
cl(1, 11).Value2 = Evaluate(Replace(F, "#", "AT"))
cl(1, 12).Value2 = cl(1, 10).Value2 + cl(1, 11).Value2
End Sub