A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
I guess, I can take B3 value from worksheet "Unique List" in the Macro workbook to fill B1 in the coversheet. If your suggested code does what is expected then go with it.
wbMacro.Sheets(2).Copy
The above code will automatically create a new workbook? from the code I see cover sheet is being copied then workbooks.add and paste is required I was hoping. No Paste required at this stage of the code. The data is populated when the code loops through the source data, sets the filter then copies and pastes the visible data.
Following code is now obsolete. It is a legacy from earlier version where we were using the InputBox. I have now deleted it.
With wsOutput
lngLastRow = LastRow(.Cells)
If lngLastRow < 4 Then lngLastRow = 4
.Range(.Rows(4), .Rows(lngLastRow)).ClearContents
End With
if LastRow(.Cells) = 4
Then Range(rows(4), Rows(4)). ClearContents I did not understand it. Code is deleted now but the reason for setting the variable to 4 was if no data (only column headers) then last used row will be 3 and we did not want to delete row 3 so set it to 4.
.Range(.Rows(4), Rows(4)) is actually row 4. If it were .Range(.Rows(4), .Rows(7)) you would understand that it is row 4 to row 7 but row 4 to row 4 is simply row 4.
In my latest code I have replaced the copy templates code. Rather than loop through sheet numbers, I have looped through all sheets and I have used a Select Case and actually identify the sheets by their name. Reason for this is in case sometime in the future the sheet positions are changed. also you might decide that you need additional sheet/s and with the modified code you only need to add the sheet names to the comma separated list. so you can find the change in the uploaded workbook, it is the following code.
wbMacro.Worksheets("Coversheet").Copy 'Copies the "Output Coversheet" worksheet to a new workbook. (New workbook is automatically added)
Set wbOutput = ActiveWorkbook 'Assign new workbook to a workbook variable. (New workbook defaults to the ActiveWorkbook)
'Note that there no need to rename the new workbook AT THIS STAGE. Simply reference by the workbook variable
'Copy remaining worksheet templates as per Case comma separated list to the new workbook (Last sheet Unique List should not be required in the Output workbook)
For Each ws In wbMacro.Worksheets
'Using Select case allows list of sheets separated by a comma for matches.
Select Case ws.Name
'Following line: If ws.Name matches any one of the names in the comma separated list then it is copied to the Output Workbook
Case "Output", "Sheet2 not required", "Static Sheet3", "Legend"
ws.Copy After:=wbOutput.Worksheets(wbOutput.Worksheets.Count)
End Select
Next ws
I have uploaded a new zipped file to the following link: Updated workbook files