-2

how to make below formula to work in VBA

lastrowA and lastrowCheck is the range i want to use

Worksheets("Investigate").Range("F & lastrowA,F" & lastrowCheck).Formula = "=SUMIFS(L$1:L$12,F$1:F$12,A&lastrowA,G$1:G$12,B&lastrowA,E$1:E$12,C&lastrowA,K$1:K$12,D&lastrowA)"
GMalc
  • 2,608
  • 1
  • 9
  • 16
Wei Chen
  • 57
  • 6
  • https://stackoverflow.com/questions/42503316/how-can-i-insert-variable-into-formula-in-vba – BigBen Mar 10 '20 at 19:19
  • 1
    For starters; your range is formatted incorrectly, should be something like this, e.g. `,Range("F" & arownumber & ":" & "F" & lastRow)` to select a valid range. Also, you seem to be using two last row variables `lastrowA` and `lastrowCheck`, you need to clarify what these two variables are. – GMalc Mar 10 '20 at 19:50

1 Answers1

0

Try:

With ThisWorkbook.Worksheets("Investigate").Range("F" & lastrowA & ":F" & lastrowCheck)
    .Formula = "=SUMIFS(L$1:L$12,F$1:F$12,A" & lastrowA & ",G$1:G$12,B" & lastrowA & ",E$1:E$12,C" & lastrowA & ",K$1:K$12,D" & lastrowA & ")"
End With
Error 1004
  • 7,877
  • 3
  • 23
  • 46