Aply a formula on a range

Philippe31

New Member
Joined
Oct 26, 2023
Messages
9
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone. I'm new in VBA and i have a issue with VBA Code
I try to copie a formula on a range of cell but it's doesn'T work,
Can you help me.
It a index formula
I want the index formula to apply for the entire range.
I don't know if I went about it the right way.


VBA Code:
Sub paste_data()


Dim lastCell As Range
Dim targetRange As Range

Set lastCell = Cells(5, Columns.Count).End(xlToLeft).Offset(0, 1)
Set targetRange = Range(lastCell, lastCell.Offset(200, 0))

targetRange.FormulaR1C1 = "=IFERROR(INDEX(Billing_Summary!R1C1:R999C2,MATCH(RC3,Billing_Summary!R1C1:R999C1,0),14),"""")"

End Sub


Thank for helping
I
 
Recheche_valeur_www.xlsm
ABCDEFGHIJ
3WPCOtestForecastForecastForecastForecast
4Work PackageFirmCLEFBASELINEmars Avrilmaijuin
52WP1xx2WP1xxert$123$123$123
63ghdfghxx3ghdfghxxert
74WP1xx4WP1xxert$13
85WP1jlp5WP1jlpert$15
96WP1xx6WP1xxert$16
107WP1xx7WP1xxert$17
118WP1xx8WP1xxert$18
12 
13 
14 
WBS
Cell Formulas
RangeFormula
I7:I14I7=IFERROR(INDEX(BS!$A$1:$ZZ$17,MATCH($A7,BS!$A$1:$A$17,0),14),"")
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Recheche_valeur_www.xlsm
ABCDEFGHIJ
3WPCOtestForecastForecastForecastForecast
4Work PackageFirmCLEFBASELINEmars Avrilmaijuin
52WP1xx2WP1xxert$123$123$123
63ghdfghxx3ghdfghxxert
74WP1xx4WP1xxert$13
85WP1jlp5WP1jlpert$15
96WP1xx6WP1xxert$16
107WP1xx7WP1xxert$17
118WP1xx8WP1xxert$18
12 
13 
WBS
Cell Formulas
RangeFormula
I7:I13I7=IFERROR(INDEX(BS!$A$1:$ZZ$17,MATCH($A7,BS!$A$1:$A$17,0),14),"")
 
Upvote 0
Did you try the macro that I put in post #8?
Please, You should try and read what I'm writing.


According to your example, the formula goes in row 5 and takes cell A7 as the first value to look for.
Try this:

VBA Code:
Sub paste_data()
  Dim lastCell As Range
  Dim targetRange As Range
  
  Set lastCell = Cells(5, Columns.Count).End(xlToLeft).Offset(0, 1)
  Set targetRange = Range(lastCell, lastCell.Offset(200, 0))
  
  targetRange.Formula = "=IFERROR(INDEX(BS!$A$1:$ZZ$999,MATCH($A7,BS!$A$1:$A$999,0),14),"""")"
End Sub

Change the 999 to the row number you want.


----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
🫡
 
Upvote 0
Did you try the macro that I put in post #8?
Please, You should try and read what I'm writing.


According to your example, the formula goes in row 5 and takes cell A7 as the first value to look for.
Try this:

VBA Code:
Sub paste_data()
  Dim lastCell As Range
  Dim targetRange As Range
 
  Set lastCell = Cells(5, Columns.Count).End(xlToLeft).Offset(0, 1)
  Set targetRange = Range(lastCell, lastCell.Offset(200, 0))
 
  targetRange.Formula = "=IFERROR(INDEX(BS!$A$1:$ZZ$999,MATCH($A7,BS!$A$1:$A$999,0),14),"""")"
End Sub

Change the 999 to the row number you want.


----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
🫡
Oh my god.

It's a long sheet. The formula work, but it's send the data to the last blank cell (coloum DD) and i want to the first blank cell (it's AM column in my sheet)!

Can you help and really sorry !

I have 62 times copies the data to the last blank cell. I propably continue until i dead ! :)
 
Upvote 0
Set lastCell = Cells(5, Columns.Count).End(xlToLeft).Offset(0, 1)
That line of the macro looks for the last column with data based on row 5.

If it is not row 5, then change the 5 to the other row number, perhaps 4 where you have your headers.

It is difficult to follow you since you are constantly changing information.

What I can suggest is that you review your sheet and delete everything to the right of column J and try again.
🫡
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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