简体   繁体   中英

Excel Formulas to excel-vba

I have this formula that looks at various criteria across multiple columns and checks to see that if all the all the criteria match, it will paste data from one column to another. I've tried a couple ways to get it into VBA, but I can't seem to get anything to work. Thanks!

=IFERROR(INDEX(Sheet1!A$2:A$205,SMALL(IF(ISNUMBER(SEARCH("ECR Approval",Sheet1!$C$2:$C$205)),ROW(Sheet1!$A$2:$A$205)-ROW(Sheet1!$A$2)+1),ROWS(A$2:A2))),"")

This is an Array Formula and you can place this formula on the Sheet by using the following code...

Dim ws As Worksheet
Set ws = Sheets("Sheet2")   'Sheet where formula would be placed
ws.Range("A2").FormulaArray = "=IFERROR(INDEX(Sheet1!A$2:A$205,SMALL(IF(ISNUMBER(SEARCH(""ECR Approval"",Sheet1!$C$2:$C$205)),ROW(Sheet1!$A$2:$A$205)-ROW(Sheet1!$A$2)+1),ROWS(A$2:A2))),"""")"
ws.Range("A2").AutoFill ws.Range("A2:A205"), xlFillDefault

To use a function in VBA, you need to use before each function Application.WorksheetFunction .

x = Application.WorksheetFunction.Sum(y,z)

To reference a cell in a sheet in VBA you can use Rage

x = Application.WorksheetFunction.Sum(Range("A1:A2"))

Put this to things Together and it would look like this:

=Application.WorksheetFunction.IFERROR(Application.WorksheetFunction.Index(Worksheet(1).Range("A2:A205"),Application.WorksheetFunction.SMALL(Application.WorksheetFunction.IF(Application.WorksheetFunction.ISNUMBER(....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM