

December 4, 2021

I am getting a 1004 error on this code. See the screenshots for the error message and where it breaks. In addition, it seems to skip over the previous code and does not add my header (Helper) to the sheet. Any help is appreciated.
Dim LastRowColumnA As Long
' Section Map
With Worksheets("Section Map")
' Headers to Add
Range("G1").Value = "Helper"
' Formula to Add
LastRowColumnA = Cells(rows.Count, 1).End(xlUp).Row
Range("G2:G" & LastRowColumnA).Formula = "=A2&"" - ""&B2)" ' Helper Formula
End With
' Match Sections
With Worksheets("Match Section")
' Formula to Add
LastRowColumnA = Cells(rows.Count, 1).End(xlUp).Row
Range("C2:C" & LastRowColumnA).Formula = "=XLOOKUP($R2,SectionMap_Helper,SectionMap_SectionHeader," - ",0,1)" ' Helper Formula
' Helper Column
' Headers to Add
Range("R1").Value = "Helper"
' Formula to Add
LastRowColumnA = Cells(rows.Count, 1).End(xlUp).Row
Range("R2:R" & LastRowColumnA).Formula = "=A2&"" - ""&B2)" ' Helper Formula
End With
End Sub


Trusted Members
Moderators

November 1, 2018

You had a few errors in that code. Try this version instead:
Private Sub FormulaFill()
Dim LastRowColumnA As Long
' Section Map
With Worksheets("Section Map")
' Headers to Add
.Range("G1").Value = "Helper"
' Formula to Add
LastRowColumnA = .Cells(rows.Count, 1).End(xlUp).Row
.Range("G2:G" & LastRowColumnA).Formula = "=A2&"" - ""&B2" ' Helper Formula
End With
' Match Sections
With Worksheets("Match Sections")
' Formula to Add
LastRowColumnA = .Cells(.rows.Count, 1).End(xlUp).Row
.Range("C2:C" & LastRowColumnA).Formula = "=XLOOKUP($R2,SectionMap_Helper,SectionMap_SectionHeader,"" - "",0,1)" ' Helper Formula
' Helper Column
' Headers to Add
.Range("R1").Value = "Helper"
' Formula to Add
LastRowColumnA = .Cells(.rows.Count, 1).End(xlUp).Row
.Range("R2:R" & LastRowColumnA).Formula = "=A2&"" - ""&B2" ' Helper Formula
End With
End Sub

Answers Post
The following users say thank you to Velouria for this useful post:
Philip Treacy1 Guest(s)
