The code below is not pasting the values found where I would like it to. The code must…
- User
The code below is not pasting the values found where I would like it to. The code must first find the first empty row in column F. After the first empty row in column F is found, then it must move down 1 more row before printing the values found.
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
' Find the first empty row in column F and move down 1 row lastRowF = wsjr.Cells(wsjr.Rows.count, "F").End(xlUp).Row If Not IsEmpty(wsjr.Cells(lastRowF, "F")) Then lastRowF = lastRowF + 1
' Add the label "Last Twenty Jobs" in column F, row lastRowF wsjr.Cells(lastRowF, 6).Value = "Last Twenty Jobs"
lastRowF = lastRowF + 1 ' move down to the next row
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 If lastRowF > 29 Then Exit For ' Stop writing after 20 jobs End If Next i
Application.ScreenUpdating = True Application.EnableEvents = True
End Sub
- Assistant
To paste the values found after the first empty row in column F and moving down 1 more row, replace the following lines:
' Find the first empty row in column F and move down 1 row lastRowF = wsjr.Cells(wsjr.Rows.count, "F").End(xlUp).Row If Not IsEmpty(wsjr.Cells(lastRowF, "F")) Then lastRowF = lastRowF + 1
' Add the label "Last Twenty Jobs" in column F, row lastRowF wsjr.Cells(lastRowF, 6).Value = "Last Twenty Jobs"
lastRowF = lastRowF + 1 ' move down to the next row
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 If lastRowF > 29 Then Exit For ' Stop writing after 20 jobs End If Next i
With the following lines:
' Find the first empty row in column F and move down 1 row lastRowF = wsjr.Cells(wsjr.Rows.Count, "F").End(xlUp).Row + 1
' Add the label "Last Twenty Jobs" in column F, row lastRowF wsjr.Cells(lastRowF, 6).Value = "Last Twenty Jobs"
lastRowF = lastRowF + 1 ' move down to the next row
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 If lastRowF > 29 Then Exit For ' Stop writing after 20 jobs End If Next i
- User
I need a vba code that will do the following.
- Assistant
Sure, please provide the requirements for the VBA code and I would be happy to help write it for you.
- User
I need a vba code that will do the following. Look for the first empty row in column F. Then after the first empty row is found, move down one more row and print the value "Last Twenty Jobs"
- Assistant
Here's the VBA code that you can use to find the first empty row in column F, move down one row, and print the value "Last Twenty Jobs":
Sub FindFirstEmptyRow() Dim lastRow As Long ' Find the first empty row in column F lastRow = Cells(Rows.Count, "F").End(xlUp).Row + 1 ' Move down one more row and print the value "Last Twenty Jobs" Cells(lastRow, "F").Value = "Last Twenty Jobs" End SubYou can run this code by clicking on the "Macros" button in the "Developer" tab in Excel, selecting the "FindFirstEmptyRow" macro, and clicking "Run".
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.