vlookup in a variable range

carstenp

Board Regular
Joined
May 27, 2010
Messages
148
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)
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,478
Latest member
Davenil

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