Formula Issue when Converting to VBA

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,589
Office Version
  1. 2021
Platform
  1. Windows
I have the following Formula in Col D (starts in D2) on sheets Fassets -This formula generates the correct result


Code:
=IFERROR(INDEX(Codes!$AC$2:$AC$9,MATCH(TRUE,ISNUMBER(SEARCH(Codes!$AB$2:$AB$9,E2)),0)),"")



I need ny VBA code amended o generate this formula in D2 , to start from Codes!$AC$2 up to last row in Col AC and also from Codes!$AB$2 up to last row in Col AB
The formula must then be copied from D2 on sheets Fassets up to the last row where there is data in Col E on sheets Fassets

Howver when running the Macro it generates this formula containing the @ symbol within the formula which is incorrect

Kindly amend my Code accordingly

Code:
 Sub Formula_Description()
Dim LR As Long, LR1 As Long
Dim lastRow As Long


With Sheets("Codes")
    lastRow = .Cells(.Rows.Count, "AB").End(xlUp).Row
End With

With Sheets("Fassets")
    LR = .Cells(.Rows.Count, "E").End(xlUp).Row
    .Range("D2:D" & LR).FormulaR1C1 = _
    "=IFERROR(INDEX(Codes!R2C29:R" & lastRow & "C29,MATCH(TRUE,ISNUMBER(SEARCH(Codes!R2C28:R" & lastRow & "C28,RC[1])),0)),"""")"
    LR1 = .Cells(.Rows.Count, "E").End(xlUp).Row
    .Range("I2:I" & LR1).FormulaR1C1 = "=EOMONTH(NOW(),-2)+1"
End With

Clear_Errors
End Sub

Sub Clear_Errors()
With Sheets("Fassets")
On Error Resume Next

.Range("D:D").SpecialCells(xlCellTypeFormulas, xlErrors).ClearContents
  End With
  
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try changing
VBA Code:
.Range("D2:D" & LR).FormulaR1C1
to
VBA Code:
.Range("D2:D" & LR).Formula2R1C1
 
Upvote 0
Solution

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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