I have a button that adds a new row to a table and enters formulas into certain cells. The full code follows:
Private Sub CommandButton1_Click()Procedure1
Procedure2
End Sub
Sub Procedure1()
sheet_name_to_create = Sheet1.Range("O3").Value
For rep = 1 To (Worksheets.Count)
If LCase(Sheets(rep).Name) = LCase(sheet_name_to_create) Then
MsgBox "This pilot already exists."
Exit Sub
End If
Next
Sheets("New Pilot").Copy After:=Sheets("Summary")
Sheets(ActiveSheet.Name).Name = sheet_name_to_create
End Sub
Sub Procedure2()
Dim the_sheets As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("Summary")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
table_object_row.Range(1, 2).Value = Range("$O$3")
table_object_row.Range(1, 3).Formula = "=LOOKUP(Summary!$A$1," & Range("$O$3").Value & "!$B$9:$B$1312," & Range("$O$3").Value & "!$L$9:$L$1312)"
table_object_row.Range(1, 4).Formula = "=LOOKUP(Summary!$A$1," & Range("$O$3").Value & "!$B$9:$B$1312," & Range("$O$3").Value & "!$N$9:$N$1312)"
table_object_row.Range(1, 9).Formula = "=LOOKUP(Summary!$A$1," & Range("$O$3").Value & "!$B$9:$B$1312," & Range("$O$3").Value & "!$I$9:$I$1312)"
table_object_row.Range(1, 10).Formula = "=SUMPRODUCT(--(" & Range("$O$3").Value & "!$B$9:$B$1312>=EDATE(TODAY()-DAY(TODAY())+1,-6))," & Range("$O$3").Value & "!$J$9:$J$1312)"
table_object_row.Range(1, 11).Formula = "=SUMPRODUCT(--(" & Range("$O$3").Value & "!$B$9:$B$1312>=EDATE(TODAY()-DAY(TODAY())+1,-6))," & Range("$O$3").Value & "!$K$9:$K$1312)"
Display More
End Sub
I need the following formula to always reference the "J" column and whatever row was just added:
table_object_row.Range(1, 5).Formula "=IF(J**CURRENTROW**>3,""GO"",""NO GO"")"
Ive tried using" & DestRow " but it is not working. But I may have it entered incorrectly.
I was able to record the following macro and, although it works, I receive an error everytime the button is pressed:
ActiveCell.FormulaR1C1 = "=IF(RC[4]>=3,""GO"",""NO GO"")"Range("F6").Select
Thank you for the help.