?
Solved

convert formula for vba use

Posted on 2014-03-13
4
Medium Priority
?
378 Views
Last Modified: 2014-03-13
How can I convert the match formula to do it in vba and assign the value to variable?
=MATCH(2,INDEX(1/(A1:A9="Apple"),0))
http://stackoverflow.com/questions/21270293/excel-vba-find-fist-and-last-occurrence-of-a-particular-value-in-a-column

Thank
0
Comment
Question by:Rayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:Rayne
ID: 39928130
Or any other excel formula that can be done in vba for the same purpose
0
 
LVL 12

Expert Comment

by:Harry Lee
ID: 39928138
You can first define a named range for the data, then enter the formula using named range.

    ActiveWorkbook.Names.Add Name:="DataRng", RefersToR1C1:="=Sheet1!R1C1:R9C1"
    Range("C2").FormulaR1C1 = "=MATCH(2,INDEX(1/(DataRng=""Apple""),0))"

Open in new window


Using named range makes your life much easier.
0
 
LVL 39

Accepted Solution

by:
nutsch earned 2000 total points
ID: 39928145
You can use this in VBA

Evaluate("=MATCH(2,INDEX(1/(A1:A9=""Apple""),0))")
0
 

Author Closing Comment

by:Rayne
ID: 39928161
awesome Sire, thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question