I created the following code to create a report for all data in the workbook that works but takes about five minutes to run. I have attached a copy of the code, but I am wondering if someone might have a better way to perform the function. I use a "Call" function to run 24 of this same code (changing search parameters "FG0100" to "FG0200", etc...).
VBA Code:
Sub IMPORT_FG0100_ALL()
Dim wsSource As Worksheet
Dim wsDestination As Worksheet
Dim lastRowSource As Long, lastRowDest As Long
Dim i As Long, j As Long
Dim cell As Range
' UNLOCK DESTINATION SHEET
Sheet152.Unprotect (CAT_PROTECT)
' BEGIN FG0100 =============================================================================================================
' Set destination worksheet
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in column A of the destination sheet
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Enter "FG-0100" into column A of the last row
Set cell = wsDestination.Cells(lastRowDest + 1, "A")
cell.value = "FG-0100 ROBOT"
' Apply formatting: bold and font size 12
With cell.Font
.Bold = True
.Size = 16
End With
' PLATFORM
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("PLATFORM-NEW")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' CONTROLS
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("CONTROLS-NEW")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' PROCESS GEAR (IPG)
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("PROCESS GEAR - IPG")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' PROCESS GEAR (NEW)
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("PROCESS GEAR-NEW")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' PROCESS GEAR (STANDARD)
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("PROCESS GEAR - STANDARD")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' TORCH
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("TORCH-NEW")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' MATERIAL FLOW
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("MATERIAL FLOW - NEW")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' MODULAR - NEW
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("MODULAR - NEW")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' CUSTOM
' Set source and destination worksheets
Set wsSource = ThisWorkbook.Worksheets("CUSTOM")
Set wsDestination = ThisWorkbook.Worksheets("JIF")
' Find the last row with data in source and destination sheets
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
lastRowDest = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row
' Loop through each row in the source sheet
For i = 1 To lastRowSource
' Check conditions: Column J = "FG0100" and Column B > 0
If wsSource.Cells(i, 2).value > 0 And wsSource.Cells(i, 10).value = "FG0100" Then
' Copy entire row to destination sheet
lastRowDest = lastRowDest + 1 ' Next empty row in destination sheet
For j = 1 To 10 ' Assuming columns A to J are to be copied
wsDestination.Cells(lastRowDest, j).value = wsSource.Cells(i, j).value
Next j
End If
Next i
' Optional: Notify the user when the process is completed
' MsgBox "Rows copied to JIF sheet.", vbInformation
' END FG0100 ===============================================================================================================
' UNLOCK DESTINATION SHEET
Sheet152.Protect (CAT_PROTECT)
End Sub