Solved

convert formula for vba use

Posted on 2014-03-13
4
366 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
  • 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now