I would like this event to paste its results starting from the last available cell in…
- User
I would like this event to paste its results starting from the last available cell in column F : Sub LastTenJobs()
Dim wscf As Worksheet Dim wsjr As Worksheet Dim lastRow As Long Dim copyRange As Range Dim cell As Range
Set wscf = Sheets(Range("G3").Value) Set wsjr = Sheets("Start Page")
Application.ScreenUpdating = True Application.EnableEvents = True Range("F5:F8").Calculate ActiveSheet.Range("F9:F60").ClearContents Application.Wait (Now + TimeValue("0:00:01")) ActiveSheet.Range("G3").Formula = ActiveSheet.Range("G3").Formula Application.Wait (Now + TimeValue("0:00:01")) ActiveSheet.Range("H3").Formula = ActiveSheet.Range("H3").Formula
If ActiveSheet.Range("G3") = "" Or 0 Then Application.ScreenUpdating = True Application.EnableEvents = True Exit Sub End If Dim LastRowJ As Long Dim lastRowF As Long Dim i As Long
Set wscf = Sheets(Range("G3").Value) Set wsjr = Sheets("Start Page")
LastRowJ = wscf.Cells(wscf.Rows.count, 10).End(xlUp).Row
If LastRowJ < 5 Then Exit Sub End If
'lastRowF = 5
'If wscf.Cells(i, 10).Value <> vbNullString Then 'wsjr.Cells(lastRowF, 6).Value = "Last Twenty Jobs" 'End If
For i = LastRowJ To 1 Step -1
If wscf.Cells(i, 10).Value <> vbNullString Then wsjr.Cells(lastRowF, 6).Value = wscf.Cells(i, 10).Value lastRowF = lastRowF + 1 End If Next i
Application.ScreenUpdating = True Application.EnableEvents = True
End Sub
- Assistant
To paste the results starting from the last available cell in column F, you can replace the following code:
'lastRowF = 5
'If wscf.Cells(i, 10).Value <> vbNullString Then 'wsjr.Cells(lastRowF, 6).Value = "Last Twenty Jobs" 'End If
For i = LastRowJ To 1 Step -1
If wscf.Cells(i, 10).Value <> vbNullString Then wsjr.Cells(lastRowF, 6).Value = wscf.Cells(i, 10).Value lastRowF = lastRowF + 1 End If Next i
with:
lastRowF = wsjr.Cells(Rows.count, "F").End(xlUp).Row + 1
For i = LastRowJ To 1 Step -1 If wscf.Cells(i, 10).Value <> vbNullString Then wsjr.Cells(lastRowF, 6).Value = wscf.Cells(i, 10).Value lastRowF = lastRowF + 1 End If Next i
This will calculate the last available row in column F of the Start Page worksheet and add 1 to it to paste the results below the last row.