Target formula with a code

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,286
Office Version
  1. 2013
Platform
  1. Windows
Code:
{=IF(ISNA(MATCH(C32,C$5:C$24,0)),"",INDEX(A$5:A$24,MATCH(C32,C$5:C$24,0)))}
{=IF(ROWS(C$32:C32)<=C$41,SMALL($C$5:$C$24,ROWS(C$32:C32)),"")}
{=IF(ISNA(MATCH(E32,C$5:C$24,0)),"",INDEX(A$5:A$24,MATCH(E32,C$5:C$24,0)))}
{=IF(ROWS(E$32:E32)<=E$41,LARGE($C$5:$C$24,ROWS(E$32:E32)),"")}

How can i target those formulas with the codes like below?
Code:
 Sheet1.Cells(32, 2).Resize(9, 1).Formula =.........
Code:
 Sheet1.Cells(32, 3).Resize(9, 1).Formula =.........
Code:
 Sheet1.Cells(32, 4).Resize(9, 1).Formula =.........
Code:
 Sheet1.Cells(32, 5).Resize(9, 1).Formula =.........

Many Thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,

For the first formula, try this

Code:
Sheet1.Cells(32, 2).Resize(9, 1).Formula = "=IF(ISNA(MATCH(C32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(C32,C$5:C$24,0)))"

The same for other formulas (observe the double quotes """"" inside the formula-string)

HTH

M.
 
Upvote 0
Perhaps this is what you mean?

<font face=Courier New><SPAN style="color:#00007F">With</SPAN> Sheet1<br>    .Cells(32, 2).FormulaArray = _<br>        "=IF(ISNA(MATCH(C32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(C32,C$5:C$24,0)))"<br>    .Cells(32, 3).FormulaArray = _<br>        "=IF(ROWS(C$32:C32)<=C$41,SMALL($C$5:$C$24,ROWS(C$32:C32)),"""")"<br>    .Cells(32, 4).FormulaArray = _<br>        "=IF(ISNA(MATCH(E32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(E32,C$5:C$24,0)))"<br>    .Cells(32, 4).FormulaArray = _<br>        "=IF(ROWS(E$32:E32)<=E$41,LARGE($C$5:$C$24,ROWS(E$32:E32)),"""")"<br>    .Cells(32, 2).Resize(9, 4).FillDown<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN></FONT>
 
Upvote 0
Perhaps this is what you mean?

With Sheet1
.Cells(32, 2).FormulaArray = _
"=IF(ISNA(MATCH(C32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(C32,C$5:C$24,0)))"
.Cells(32, 3).FormulaArray = _
"=IF(ROWS(C$32:C32)<=C$41,SMALL($C$5:$C$24,ROWS(C$32:C32)),"""")"
.Cells(32, 4).FormulaArray = _
"=IF(ISNA(MATCH(E32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(E32,C$5:C$24,0)))"
.Cells(32, 4).FormulaArray = _
"=IF(ROWS(E$32:E32)<=E$41,LARGE($C$5:$C$24,ROWS(E$32:E32)),"""")"
.Cells(32, 2).Resize(9, 4).FillDown
End With

Code:
With Sheet1
    .Cells(32, 2).FormulaArray = _
        "=IF(ISNA(MATCH(C32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(C32,C$5:C$24,0)))"
    .Cells(32, 3).FormulaArray = _
        "=IF(ROWS(C$32:C32)<=C$41,SMALL($C$5:$C$24,ROWS(C$32:C32)),"""")"
    .Cells(32, 4).FormulaArray = _
        "=IF(ISNA(MATCH(E32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(E32,C$5:C$24,0)))"
    .Cells(32, 5).FormulaArray = _
        "=IF(ROWS(E$32:E32)<=E$41,LARGE($C$5:$C$24,ROWS(E$32:E32)),"""")"
    .Cells(32, 2).Resize(9, 4).FillDown
End With

Thats Great
Thanks Peter
 
Upvote 0
Perhaps this is what you mean?

With Sheet1
.Cells(32, 2).FormulaArray = _
"=IF(ISNA(MATCH(C32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(C32,C$5:C$24,0)))"
.Cells(32, 3).FormulaArray = _
"=IF(ROWS(C$32:C32)<=C$41,SMALL($C$5:$C$24,ROWS(C$32:C32)),"""")"
.Cells(32, 4).FormulaArray = _
"=IF(ISNA(MATCH(E32,C$5:C$24,0)),"""",INDEX(A$5:A$24,MATCH(E32,C$5:C$24,0)))"
.Cells(32, 4).FormulaArray = _
"=IF(ROWS(E$32:E32)<=E$41,LARGE($C$5:$C$24,ROWS(E$32:E32)),"""")"
.Cells(32, 2).Resize(9, 4).FillDown
End With


Code:
{=COUNTIF(C5:C24,"<0")}
{=COUNTIF(C5:C24,">0")}

Peter im trynig the same way for the formulas giving above.It is giving error!
Do i miss something?
For the first formula range should be C41
For the SECOND formula range should be E41
Cheers
 
Upvote 0
Code:
{=COUNTIF(C5:C24,"<0")}
{=COUNTIF(C5:C24,">0")}

Peter im trynig the same way for the formulas giving above.It is giving error!
Do i miss something?
For the first formula range should be C41
For the SECOND formula range should be E41
Cheers
1. Why are you using array formulas? It seems you are simply trying to count cells in a range with a given condition.

2. Please post the whole code that you are using for this new task.

3. What is the error?
- Is the code giving an error? If so, what is the error message and what line is causing the error when you 'Debug'?
- Or is it the formula returning an error? If so, what error?
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,752
Members
452,940
Latest member
rootytrip

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