Put something in the last row plus 2

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
Dim Lrow As Long
Lrow = Cells(Rows.Count, "A").End(xlUp).Row


Range("A" & Lrow + 2).Select
ActiveCell.FormulaR1C1 = "54_TPL_01_02_Summary"

Shouldn't this be finding the last row and then selecting two rows lower? Its not. Its finding the last row and selecting one below it to put in the information
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I don't see how that could be happening. Try this:
Code:
[COLOR=#333333]Dim Lrow As Long[/COLOR]
[COLOR=#333333]Lrow = Cells(Rows.Count, "A").End(xlUp).Row[/COLOR]
MsgBox "The last row is " & Lrow

[COLOR=#333333]Range("A" & Lrow + 2)[/COLOR][COLOR=#333333] = "54_TPL_01_02_Summary"[/COLOR]
and see what the message box returns and if you agree that is the last row with data in column A
 
Upvote 0
If I add your code to mine, it does not put it two down.
Code:
Sub Add_Validation_Formulas()

    Dim Lrow As Long
    Lrow = Cells(Rows.Count, "A").End(xlUp).Row
    
    'From each tab listed in column A get values from the Resource totals (L3:L7)
    Range("B3:B" & Lrow).FormulaR1C1 = "=IFERROR((INDIRECT(RC1&""!$L$3"")),"""")"
    Range("C3:C" & Lrow).FormulaR1C1 = "=IFERROR((INDIRECT(RC1&""!$L$4"")),"""")"
    Range("D3:D" & Lrow).FormulaR1C1 = "=IFERROR((INDIRECT(RC1&""!$L$5"")),"""")"
    Range("E3:E" & Lrow).FormulaR1C1 = "=IFERROR((INDIRECT(RC1&""!$L$6"")),"""")"
    Range("F3:F" & Lrow).FormulaR1C1 = "=IFERROR((INDIRECT(RC1&""!$L$7"")),"""")"
    Range("G3:G" & Lrow).FormulaR1C1 = "=SUM(RC[-5]:RC[-1])"
    Range("I3:I" & Lrow).FormulaR1C1 = "=IFERROR((SUM(INDIRECT(RC1&""!$L$11:$L$5000""))),"""")"
    Range("K3:K" & Lrow).FormulaR1C1 = _
        "=IF(RC9<>RC7,""Check the tab that’s listed in column A.  The Sum of the Resouce Types do not equal the total value in Column L for that tab"","""")"


        With Cells(Lrow, 1).Offset(1)
    .Formula = "IMPORT TAB TOTALS >"
    End With
        With Cells(Lrow, 2).Offset(1)
    .Formula = "=SUM(B3:B" & Lrow & ")"
    End With
        With Cells(Lrow, 3).Offset(1)
    .Formula = "=SUM(C3:C" & Lrow & ")"
    End With
        With Cells(Lrow, 4).Offset(1)
    .Formula = "=SUM(D3:D" & Lrow & ")"
    End With
        With Cells(Lrow, 5).Offset(1)
    .Formula = "=SUM(E3:E" & Lrow & ")"
    End With
        With Cells(Lrow, 6).Offset(1)
    .Formula = "=SUM(F3:F" & Lrow & ")"
    End With
        With Cells(Lrow, 7).Offset(1)
    .Formula = "=SUM(G3:G" & Lrow & ")"
    End With
        With Cells(Lrow, 9).Offset(1)
    .Formula = "=SUM(I3:I" & Lrow & ")"
    End With

    
MsgBox "The last row is " & Lrow

Range("A" & Lrow + 2) = "54_TPL_01_02_Summary"


End Sub
 
Last edited:
Upvote 0
Obviously if I put +3 I get the desired results. But my problem is that I want to put formulas to the right of it like I did with the "With Cells"

With Cells(Lrow, 2).Offset(1)
.Formula = "=IFERROR((INDIRECT(RC1&""!$L$3"")),"""")"
End With
With Cells(Lrow, 3).Offset(1)
.Formula = "=IFERROR((INDIRECT(RC1&""!$L$4"")),"""")"
End With

As I am sure you know - doesn't work UGH!
 
Upvote 0
Let's follow the logic in post #3 that you made.

You are calculating the last row (let's say for example, it is row 10).
Then using formulas like:
Code:
With Cells(Lrow, 1).Offset(1)
You are posting formulas in the next row down (which would be row 11).

Then you are placing this formula at the very end:
Code:
Range("A" & Lrow + 2) = "54_TPL_01_02_Summary"
Which would be placing it in row 12 (Lrow +2).

Note that Lrow is not a fluid value. Once you set it at the top, it will hold that value, no matter what else you add to the range, unless you recalculate the Lrow value after you add more formulas/rows to the range.
 
Upvote 0
Thanks Joe.

THIS I DID NOT KNOW:

"Note that Lrow is not a fluid value. Once you set it at the top, it will hold that value, no matter what else you add to the range, unless you recalculate the Lrow value after you add more formulas/rows to the range."
 
Upvote 0
The key hint is how it is defined:
Code:
Dim Lrow as Long
It is being defined as number (Long Integer). Once set, those (numbers) do not change, unless reset or recalculated later in your code.
So if you are inserting a new row under it, to insert another entry 2 rows down from that, you would need to add 3.
 
Upvote 0
Joe;

So what defines the worksheet in this formula? Is it automatically the active sheet?
 
Upvote 0
So what defines the worksheet in this formula? Is it automatically the active sheet?
If there is no sheet reference in the code, it will default to the ActiveSheet at the time that part of the code is hit.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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