Here's my problem. I have a range that will move down to include all the records with the same value in column 2, however, when I try to lookup a value in this range after the first range has changed, I get an error. I don't know if it helps, but for j=1 c1=2 and c2=143, for j=2, c1=144 and c2=323, etc. Any help is greatly appreciated.
Code:
max = Application.max(rng2)
For j = 1 To max
'k is the number of rows for that specific well enabling us to set the variable range to that number of rows
k = Application.CountIf(rng2, j)
If c2 > 0 Then
c1 = c2 + 1
Else: c1 = 2
End If
c2 = c1 + (k - 1)
'^^^above checks out
Set rngcurrent = Range(Cells(c1, 13), Cells(c2, 20))
MsgBox Range(Cells(c1, 13), Cells(c2, 20)).Address
'For q = c1 To c2
'ThisWorkbook.Worksheets("Washington, Wetzel, Upshur, & L").Cells(q, 19).Value = GPSLAT
'ThisWorkbook.Worksheets("Washington, Wetzel, Upshur, & L").Cells(q, 20).Value = GPSLONG
'Next q
'Interpolate for N-S and E-W at the same depth as input for others
' b3 = zD
' b1 = Application.Large(rngcurrent, Application.CountIf(rngcurrent, ">" & b3) + 1)
' b2 = Application.Small(rngcurrent, Application.CountIf(rngcurrent, "<" & b3) + 1)
' n_s1 = Application.VLookup(b1, rngcurrent, 14, True)
' n_s2 = Application.VLookup(b2, rngcurrent, 14, True)
' If b3 - b1 = 0 Then
' n_s3 = n_s1
' Else
' n_s3 = n_s1 + (b3 - b1) * ((n_s2 - n_s1) / (b2 - b1))
' End If
' e_w1 = Application.VLookup(b1, rngcurrent, 15, True)
' e_w2 = Application.VLookup(b2, rngcurrent, 15, True)
' e_w3 = e_w1 + (b3 - b1) * ((e_w2 - e_w1) / (b2 - b1))
' zB = zD
zB = Application.VLookup(zD, rngcurrent, 1, True)
n_s3 = Application.VLookup(zB, rngcurrent, 2, True)
e_w3 = Application.VLookup(zB, rngcurrent, 3, True)