Find a value in a column, then find the next value

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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Untested, but try
Code:
Sub PlaceData()

Dim rng As Range
Dim cl As Range
Dim sFind As String
Dim i As Long
Dim ary(1 To 2) As Variant

sFind = Range("C1").Value
ary(1) = "F1"
ary(2) = "G1"
Set cl = Range("B4")
Set rng = Range("B4", Range("B65536").End(xlUp))
For i = 1 To 2
   Set cl = rng.Find(sFind, cl, xlValues, xlWhole, xlByRows, xlNext, False, , False)
     Const F = "SUMPRODUCT((MONTH(Data!A2:A2000)=@)*(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(Replace(F, "#", V(C)), "@", ary(i)))
       Next
           cl(1, 10).Value2 = Application.Sum(cl(1, 2).Resize(, 8))
           cl(1, 11).Value2 = Evaluate(Replace(Replace(F, "#", "AT"), "@", ary(i)))
           cl(1, 12).Value2 = cl(1, 10).Value2 + cl(1, 11).Value2
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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