I'm new to using VBA, and have been trying to consult articles, however; I still have an issue.
I'm building out a project tracker for my team, with a high level overview on the first sheet, and then for each Project there is an associated sheet that contains a detailed tracker. (i.e. Project 1, Project 2, Project 3 show as rows in the first sheet, and then Project 1 has it's own sheet, Project 2 has it's own sheet, etc.)
I am trying to automate updates to this tracker, as each time a new row is added to the high level tracker, I want to copy specific non contiguous cells and paste the values in the associated sheet.
My first attempt was to be able to complete this task for the first project in the tracker, and then I'll add subsequent macros later after I adjust the code. However, when I run the following macro there are no errors but there are no outputs into the specified destination.
Some other things to note:
- For high level tracking file, Project 1 goes from cells A9:A10, Project 2 goes from cells A13:A18, and so on.. they are one on top of the other
- An issue in my current code is also that I am specifically calling out cells to create an array with. I would imagine that once I successfully run this, for the next added project task, I would have to manually adjust these call outs. Any advice to circumvent that would also be appreciated..
The following is my code
Sub Update_Project_1()
Dim LR As Long, i As Long, cls
Dim wscopy As Worksheet
Dim wspaste As Worksheet
Set wscopy = Workbooks("Project_Tracker.xlsm").Worksheets("High Level Tracker")
Set wspaste = Workbooks("Project_Tracker.xlsm").Worksheets(" Project 1 Detailed Tracker")
With wscopy
cls = Array("A10", "B10", "C10", "F10", "H10")
End With
With wspaste
LR = WorksheetFunction.Max(4, .Range("A" & Rows.Count).End(xlUp).Row + 1)
Debug.Print LR
For i = LBound(cls) To UBound(cls)
.Cells(LR, i + 1).Value = wspaste.Range(cls(i)).Value
Next i
End With
End Sub
Any advice would be greatly appreciated, thanks in advance!
question from:
https://stackoverflow.com/questions/65894146/attempting-to-copy-most-recent-non-contiguous-cells-in-a-range-and-paste-into-a 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…