Forum

VBA - Inserting For...
 
Notifications
Clear all

VBA - Inserting Formula, getting Object-defined Error

3 Posts
2 Users
0 Reactions
107 Views
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

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.

 

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 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

 
Posted : 05/03/2022 3:10 pm
(@debaser)
Posts: 836
Member Moderator
 

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

 
Posted : 07/03/2022 6:19 pm
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

@Velouria

 

Thanks so very much.  Your code revision worked perfectly!!!  I really appreciate it!!!!

 
Posted : 15/03/2022 1:00 pm
Share: