offset with vba

kkjensen

Active Member
Joined
Jun 22, 2004
Messages
354
hi there.

I've got a table (well, not really...a series of data sets on one sheet) that I need to use.

I'm writing a macro/function to find the right dataset and then return the range of one of the columns under it.

Each data set has 2 columns, a title above it and an undetermined number of lines like this:
ChartRef.xls
ABCDEFGHI
1full2-a1-a
2
30.009.050.009.050.007.07
40.059.060.059.060.067.11
50.109.130.109.130.127.19
60.149.140.149.140.217.40
70.189.210.189.210.247.50
80.239.350.239.350.297.70
90.279.420.279.450.317.84
100.309.550.309.550.368.04
110.329.620.329.620.418.18
120.339.690.349.630.488.39
130.369.790.369.700.538.59
140.379.900.389.760.568.70
150.409.930.419.800.598.87
160.4310.030.439.870.619.00
170.4510.140.469.940.639.14
180.4910.370.5110.080.669.27
190.5310.680.5410.180.689.41
200.5710.980.5610.280.729.54
210.6011.280.5910.450.769.71
220.6311.420.6310.620.799.82
230.6711.590.6510.760.829.99
240.7011.790.6810.930.8510.12
250.7312.020.7211.200.8810.26
260.7612.190.7411.330.9110.43
270.8012.530.7611.530.9310.56
280.8412.860.7811.600.9710.83
290.8813.270.8111.671.0010.97
300.9113.600.8311.77
310.9514.100.8711.91
320.9814.570.9212.15
331.0014.870.9512.28
340.9812.45
351.0012.59
36
Panel_Buckling


In a normal worksheet, I could do an index lookup in one of these sets using
- match to find the right title in the first row
- offset to return ranges for each of the two desired columns
- match to find the desired row in the first column
- index to return the corresponding row of the second column

Here's an example I threw together using the above data set. I find the "full" set, then find the 2nd column entry corresponding with 0.30 (ignore that I linked directly to this number...normally that would come from another cell).

Code:
=INDEX(OFFSET(A1,2,MATCH("full",1:1,0),100,1),MATCH(B10,OFFSET(A1,2,MATCH("full",1:1,0)-1,100,1),0))

How would I do this in vba? I'm not seeing functions like "offset" in the application.worksheetfunction object browser. I'm planning on putting these worksheets full of data into an add-in so I also am going to be using "indirect", which I don't see either. Here's what it looks like with the indirect references...and is what I'm trying to duplicate in VBA.
Code:
=INDEX(OFFSET(INDIRECT("'[ChartRef.xla]"&G25&"'!$A$1"),2,MATCH(I25,INDIRECT("'[ChartRef.xla]"&G25&"'!$1:$1"),0),100,1),MATCH(J25,OFFSET(INDIRECT("'[ChartRef.xla]"&G25&"'!$A$1"),2,MATCH(I25,INDIRECT("'[ChartRef.xla]"&G25&"'!$1:$1"),0)-1,100,1),0))
<*phew*>...anyway, to avoid having to type this more than once, I've decided to put the reference tables and the functions to hunt through them into an add-in so I just need to use a function like "chartref(sheetname,tablename,value)" to get what the corresponding value back out.

Summary: indirect and offset in vba??????
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Offset in VBA is a property of a Range. So something like
Code:
Range("$A$1").Offset(0,1)
to identify B1

lenze
 
Upvote 0
Thanks for the reply

Can that be combined with "indirect"? In my last equation there I build the reference for a cell [addinname.xla]sheetnamewhateveritmaybe!$A$1 and then offset it.

I've only seen offset when I've recorded things but it generally looked like:
Code:
Activecell.Offset(0,1).Range("A1").Select
where yours is range then offset...in order to get a range that is off to one side, would it look like
Code:
Range("$A$1").Offset(0,1).Range("A1:A100")
??? I'm trying to return a range that can be used with index.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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