Need to Adjust Macro Formula

floridagunner

Board Regular
Joined
Jul 20, 2007
Messages
60
Hello I am trying to write a macro that will insert a formula directly into the cells in column M of my worksheet.

The worksheet has about 3400 rows. When I run the macro it does not adjust the cell reference in the formula so I am getting the same value in all 3400 rows.

I am using the following code:

Code:
Sub InsertFormula4()
With Sheets("FILE 1 C")
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("M2:M" & LastRow).FormulaArray = "=INDEX('FA SPLIT MASTER'!$A$1:$J$57670,SMALL(IF('FA SPLIT MASTER'!$A$1:$J$57670=$A2,ROW('FA SPLIT MASTER'!$A$1:$J$57670)),MOD(COUNTIF($A$2:$A2,$A2)-1,COUNTIF('FA SPLIT MASTER'!$A$1:$A$57670,$A2))+1),6)"
End With
Range("M2").Select
End Sub

The formula that I am using in the code above was written for Cell M2. And my problem is that it brings back exactly the same value in all the cells in Column M.

I hope somebody can point out what I am doing wrong.

Thanks
floridagunner
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Just:
Range("M2").Copy Destination:=Range("M2:M3400")

Or:
Range("M2").Autofill Destination:=Range("M2:M3400")

Note: You can get code like this pretty easily with the macro recorder - its a great tool for getting syntax.

Regards
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,930
Members
449,479
Latest member
nana abanyin

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