Hi, I'm a VBA newb and need some expert help please.
I've got the following already but I need the part after "'COPY DATA FROM qryHIRES TO EA INTEL LIGHT" only if the data doesn't already exist in the second sheet. What do I need to add?
Sub EALightReport()
'
' EALightReport Macro
' ENTER YES, DATE AND NAME
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "A").End(xlUp).Row ' <-- get last row in column "A"
.Range("A" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = "Yes"
Windows("qryHires_onHire.xlsm").Activate
End With
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "B").End(xlUp).Row ' <-- get last row in column "B"
.Range("B" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("B" & Rows.Count).End(xlUp).Offset(1, 0) = Format(Date, "DD/MM/YY")
Windows("qryHires_onHire.xlsm").Activate
End With
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "C").End(xlUp).Row ' <-- get last row in column "C"
.Range("C" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("C" & Rows.Count).End(xlUp).Offset(1, 0) = Application.UserName
Windows("qryHires_onHire.xlsm").Activate
End With
'COPY DATA FROM qryHIRES TO EA INTEL LIGHT
Range("B143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "D").End(xlUp).Row ' <-- get last row in column "D"
.Range("D" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("D" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("C143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "E").End(xlUp).Row ' <-- get last row in column "E"
.Range("E" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("E143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "F").End(xlUp).Row ' <-- get last row in column "F"
.Range("F" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("F" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("F143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "G").End(xlUp).Row ' <-- get last row in column "G"
.Range("G" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("G" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("I143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "H").End(xlUp).Row ' <-- get last row in column "H"
.Range("H" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("H" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("K143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "I").End(xlUp).Row ' <-- get last row in column "I"
.Range("I" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("I" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("N143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "K").End(xlUp).Row ' <-- get last row in column "K"
.Range("K" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("K" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("O143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "L").End(xlUp).Row ' <-- get last row in column "L"
.Range("L" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("L" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("P143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "M").End(xlUp).Row ' <-- get last row in column "M"
.Range("M" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("M" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("Q143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "N").End(xlUp).Row ' <-- get last row in column "N"
.Range("N" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("N" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("R143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "O").End(xlUp).Row ' <-- get last row in column "O"
.Range("O" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("O" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("T143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "Q").End(xlUp).Row ' <-- get last row in column "Q"
.Range("Q" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("Q" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
End Sub
I've got the following already but I need the part after "'COPY DATA FROM qryHIRES TO EA INTEL LIGHT" only if the data doesn't already exist in the second sheet. What do I need to add?
Sub EALightReport()
'
' EALightReport Macro
' ENTER YES, DATE AND NAME
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "A").End(xlUp).Row ' <-- get last row in column "A"
.Range("A" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = "Yes"
Windows("qryHires_onHire.xlsm").Activate
End With
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "B").End(xlUp).Row ' <-- get last row in column "B"
.Range("B" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("B" & Rows.Count).End(xlUp).Offset(1, 0) = Format(Date, "DD/MM/YY")
Windows("qryHires_onHire.xlsm").Activate
End With
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "C").End(xlUp).Row ' <-- get last row in column "C"
.Range("C" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("C" & Rows.Count).End(xlUp).Offset(1, 0) = Application.UserName
Windows("qryHires_onHire.xlsm").Activate
End With
'COPY DATA FROM qryHIRES TO EA INTEL LIGHT
Range("B143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "D").End(xlUp).Row ' <-- get last row in column "D"
.Range("D" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("D" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("C143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "E").End(xlUp).Row ' <-- get last row in column "E"
.Range("E" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("E143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "F").End(xlUp).Row ' <-- get last row in column "F"
.Range("F" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("F" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("F143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "G").End(xlUp).Row ' <-- get last row in column "G"
.Range("G" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("G" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("I143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "H").End(xlUp).Row ' <-- get last row in column "H"
.Range("H" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("H" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("K143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "I").End(xlUp).Row ' <-- get last row in column "I"
.Range("I" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("I" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("N143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "K").End(xlUp).Row ' <-- get last row in column "K"
.Range("K" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("K" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("O143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "L").End(xlUp).Row ' <-- get last row in column "L"
.Range("L" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("L" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("P143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "M").End(xlUp).Row ' <-- get last row in column "M"
.Range("M" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("M" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("Q143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "N").End(xlUp).Row ' <-- get last row in column "N"
.Range("N" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("N" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("R143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "O").End(xlUp).Row ' <-- get last row in column "O"
.Range("O" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("O" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
Range("T143").Select
Selection.Copy
Windows("EA Intelligent Lights.xlsx").Activate
With Workbooks("EA Intelligent Lights.xlsx").Worksheets("2023")
RowCount = .Cells(.Rows.Count, "Q").End(xlUp).Row ' <-- get last row in column "Q"
.Range("Q" & RowCount + 1) = workOrderDescription
Sheets("2023").Range("Q" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Windows("qryHires_onHire.xlsm").Activate
End With
End Sub