selecting a range in a macro

mish78

New Member
Joined
Apr 27, 2009
Messages
12
Hi,
I am trying to select a range in a macro where the first cell position will be returned by a formula.

In excel =CELL("address",INDEX(E6:J6,1, MATCH(customer,E6:J6))) would give me $F$6 which is the location of the cell that has customer in it.

I am trying to use it in a macro but keep getting method range of object global failed. Is there any other way of selecting a range with the first cell value as a search.
e.g
Range("CELL('address',INDEX(E6:J6,1,MATCH(customer,E6:J6))):AA1000").Select

Thanks in advance
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
A couple of possibilities:

Code:
Sub Test1()
    Range(Evaluate("=CELL(""address"",INDEX(E6:J6,1, MATCH(customer,E6:J6)))") & ":AA1000").Select
    MsgBox Selection.Address
End Sub
 
Sub Test2()
    Range(Range("E6:J6").Cells(1, WorksheetFunction.Match(Range("customer"), Range("E6:J6"))).Address & ":AA1000").Select
    MsgBox Selection.Address
End Sub
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,588
Messages
5,765,303
Members
425,271
Latest member
kristyfinn

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
Top