Home > Enterprise >  Dim lastrow As Long - adding multiple values to rows at the bottom of data
Dim lastrow As Long - adding multiple values to rows at the bottom of data

Time:11-24

I have created a spreadsheet to format some raw data, and would like to insert the below in column F once the last row is found.

TOTALS
YTD Dividends
(row in between)
YTD Interest
(row in between)
YTD Gain/Loss

Used the below to get the TOTALS, but cannot figure out how to add the additional titles below in column F. Is this not possible because i am using last row? The amount of rows will vary for each spreadsheet so i need to find the end and insert the values.

'...
End With
    Dim lastrow As Long
    lastrow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row   2
    With Selection
    ActiveSheet.Cells(lastrow, "F").Value = "TOTALS"
    End With
End Sub

CodePudding user response:

You could do it like this:


    '...
    End With

    'offset 2 rows down and 2 columns to the right
    With ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Offset(2, 2)
        .Value = "TOTALS"
        .Offset(1).Value = "YTD Dividends"
        .Offset(3).Value = "YTD Interest"
        .Offset(5).Value = "YTD Gain/Loss"
    End With
    
End Sub
  • Related