I've been trying to work through this but have not been successful so far. The code works, but in unintended ways unfortunately.
The MACRO workbook is the master workbook with all data fields on the "Data" sheet. The LEAN workbook contains certain data points that I'd like to copy and paste into named ranges on the "Data" sheet within the MACRO workbook to the last row available.
For ex:
Macro Workbook has columns:
Eng # Eng Name Date Started Date Completed KPI1 KPI2
100 ABC 12/01/2018 12/10/2018 50 100
Lean Workbook has columns:
Eng # Date Started Date Completed KPI# Score
101 12/02/2018 12/03/2018 1 50
101 12/02/2018 12/03/2018 2 10
102 11/01/2018 11/20/2018 1 100
102 11/01/2018 11/20/2018 4 100
The goal is two-fold:
- Grab data from the Lean workbook's specific columns and paste into the Macro workbook's "Data" sheet to the last row available
- Grab the KPI # from the Lean Workbook (which are in rows) and past the score to the named ranges/columns that match the KPI # in the "Data" sheet.
My attempt at the code below:
Public Sub GrabLeanFileData()
Dim wbmacro As Workbook
Dim wblean As Workbook
Set wbmacro = Workbooks.Item("MacroFile.xlsm")
Set wblean = Workbooks.Item("Subcontractor CA - KPI's Lean.csv")
Dim wsmacro As Worksheet
Dim wslean As Worksheet
Set wsmacro = wbmacro.Worksheets.Item("Data")
Set wslean = wblean.Worksheets.Item("Subcontractor CA - KPI's Lean")
Dim leanrange As Range
Set leanrange = wslean.Range("A2:A15000")
wblean.Activate
Dim cell As Range
i = 1
For Each cell In leanrange
If leanrange.Range("A2") <> "E1002" Then
Range("A2").Offset(i, 0).Value = wsmacro.Range("Enum").Value
Range("B2").Offset(i, 0).Value = wsmacro.Range("ds").Value
Range("C2").Offset(i, 0).Value = wsmacro.Range("dc").Value
Range("D2").Offset(i, 0).Value = wsmacro.Range("kpi1").Value
i = i + 1
End If
Next cell
End Sub
I wanted to skip the test Eng # of 1002 so i put that condition in.
cell
in yourFor Each
loop but you never use it in your loop. – dwironywslean.Range("A2").Offset(i,0)
? Just a guess. Without knowing what your code is outputting, it's hard to identify the problem. – C Dieguezwsmacro.Range("enum")
your column header? If so, I think you've just got the syntax reversed. Doeswsmacro.Range("enum") = wslean.Range("A2").Offset(i,0)
solve the problem? – C Dieguez