I recently was given the task of maintaining (and correcting) a spreadsheet used by multiple individuals in the company.
I was hoping someone could help this rookie understand the commands.
What this is intended to do, is import data from a "Source File" into specific tabs on the worksheet containing this code.
What I don't understand is where the code spells out what cells to copy and where to paste them to.
Been trying to get my employer to send me for "Offical" training, but until then hoping someone here can educate me.
See below:
I was hoping someone could help this rookie understand the commands.
What this is intended to do, is import data from a "Source File" into specific tabs on the worksheet containing this code.
What I don't understand is where the code spells out what cells to copy and where to paste them to.
Been trying to get my employer to send me for "Offical" training, but until then hoping someone here can educate me.
See below:
VBA Code:
Public Sub UpdateSelections()
Dim tmpRow As Integer
Dim tmpLastRow As Integer
Dim tmpIntVar As Integer, tmpLoop2 As Integer
ActiveWorkbook.Sheets("UPDATE").Unprotect (CAT_PROTECT)
'find the last row used
tmpRow = ActiveWorkbook.Sheets("UPDATE").UsedRange.Rows.Count
tmpRow = tmpRow + 1
'Platform Items
tmpLastRow = ActiveWorkbook.Sheets("Platform").Range("Total_Platform").Row
For tmpIntVar = 3 To tmpLastRow
If ActiveWorkbook.Sheets("Platform").Cells(tmpIntVar, 2) <> "" Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("Platform").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("Platform").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "Platform"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
'Robot Items
' this sheet contains a formula in some of the quantity cells
tmpLastRow = ActiveWorkbook.Sheets("Robot").Range("Total_Robot").Row
For tmpIntVar = 3 To tmpLastRow
If ActiveWorkbook.Sheets("Robot").Cells(tmpIntVar, 2) <> "" And _
ActiveWorkbook.Sheets("Robot").Cells(tmpIntVar, 2) <> "0" Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("Robot").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("Robot").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "Robot"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
'process & torch
' this sheet contains a formula in some of the quantity cells
tmpLastRow = ActiveWorkbook.Sheets("Process & Torch").Range("Total_process").Row
For tmpIntVar = 3 To tmpLastRow
If ActiveWorkbook.Sheets("Process & Torch").Cells(tmpIntVar, 2) <> "" And _
ActiveWorkbook.Sheets("Process & Torch").Cells(tmpIntVar, 2) <> "0" Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("Process & Torch").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("Process & Torch").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "Process & Torch"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
'Controls
' this sheet contains a formula in some of the quantity cells
tmpLastRow = ActiveWorkbook.Sheets("Controls").Range("Total_controls").Row
For tmpIntVar = 3 To tmpLastRow
If ActiveWorkbook.Sheets("Controls").Cells(tmpIntVar, 2) <> "" And _
ActiveWorkbook.Sheets("Controls").Cells(tmpIntVar, 2) <> "0" Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("Controls").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("Controls").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "Controls"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
'material handling items
tmpLastRow = ActiveWorkbook.Sheets("Mat. Flow").Range("Total_Material_Flow").Row
For tmpIntVar = 3 To tmpLastRow
If ActiveWorkbook.Sheets("Mat. Flow").Cells(tmpIntVar, 2) <> "" Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("Mat. Flow").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("Mat. Flow").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "Mat. Flow"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
'Custom
' this sheet starts on the 4th row instead of the 3rd row (buttons in row 1)
tmpLastRow = ActiveWorkbook.Sheets("Custom").Range("Total_Custom").Row
For tmpIntVar = 4 To tmpLastRow
If ActiveWorkbook.Sheets("Custom").Cells(tmpIntVar, 2) <> "" Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("Custom").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("Custom").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "Custom"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
'Modular
tmpLastRow = ActiveWorkbook.Sheets("Modular").Range("Total_Modular").Row
For tmpIntVar = 3 To tmpLastRow
If ActiveWorkbook.Sheets("Modular").Cells(tmpIntVar, 2) <> "" And _
ActiveWorkbook.Sheets("Modular").Cells(tmpIntVar, 2).Value <> 0 Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("Modular").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("Modular").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "Modular"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
'Spot Weld
tmpLastRow = ActiveWorkbook.Sheets("spot_weld").Range("Total_spot_weld").Row
For tmpIntVar = 3 To tmpLastRow
If ActiveWorkbook.Sheets("spot_weld").Cells(tmpIntVar, 2) <> "" Then
'copy most of the row
For tmpLoop2 = 1 To 11
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, tmpLoop2) = _
ActiveWorkbook.Sheets("spot_weld").Cells(tmpIntVar, tmpLoop2)
Next tmpLoop2
' 'replace the quantity with the formula
' ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 2).Formula = _
' ActiveWorkbook.Sheets("spot weld").Cells(tmpIntVar, 2).Formula
'removed the formulas - they were creating circular references
'added information - used later for comparison
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 12) = "spot_weld"
ActiveWorkbook.Sheets("UPDATE").Cells(tmpRow, 13) = ActiveWorkbook.Sheets("Summary").Cells(4, 2)
tmpRow = tmpRow + 1
End If
Next tmpIntVar
ActiveWorkbook.Sheets("UPDATE").Protect (CAT_PROTECT)
End Sub
Last edited by a moderator: