beartooth91
New Member
- Joined
- Dec 15, 2024
- Messages
- 46
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
So.....the code below works....as long as the copy from sheet is selected. (If the copy to sheet is selected, while running the procedure; nothing is copied.) This is a common problem I've had when copying between sheets and/or workbooks using With Statements. I need to paste values as some of the data contains formulas or lookups. As I said; the code works, but lots of forum readings say you're not supposed to use 'Activate' and 'Select'.
VBA Code:
Sub Copy_Master()
'
'Copies point info from Master IO List Workbook to the Imported sheet in the Master Database Workbook
'
Application.ScreenUpdating = False
Call Clear_Imported
Call Open_Master_IO
'
'Count rows of data in NIC Master IO List worksheet
Dim a As Long, b As Long, entry As Range
a = Workbooks("NIC Master IO List.xlsm").Worksheets("NIC Master IO List").Range("B" & Rows.Count).End(xlUp).Row
'
'Determine start row to paste in Imported worksheet of Master Database Workbook
'
'Workbooks("NIC Master IO List.xlsm").Worksheets("NIC Master IO List").Range("B11:BP" & a).Copy
'Workbooks("NIC Master Database.xlsm").Worksheets("Imported").Range("B11:BP" & b).PasteSpecial Paste:=xlPasteValues 'xlPasteAll
Workbooks("NIC Master IO List.xlsm").Worksheets("NIC Master IO List").Activate
With Workbooks("NIC Master IO List.xlsm").Worksheets("NIC Master IO List")
For Each entry In Range("BP11:BP" & a)
If entry.Value = "Valid" Then
b = Workbooks("NIC Master Database.xlsm").Worksheets("Imported").Range("B" & Rows.Count).End(xlUp).Row + 1
entry.EntireRow.Copy 'Destination:=Workbooks("NIC Master Database.xlsm").Worksheets("Imported").Range("A" & b)
Workbooks("NIC Master Database.xlsm").Worksheets("Imported").Activate
Workbooks("NIC Master Database.xlsm").Worksheets("Imported").Range("A" & b).PasteSpecial Paste:=xlPasteValues
Workbooks("NIC Master IO List.xlsm").Worksheets("NIC Master IO List").Activate
End If
Next entry
End With
Application.CutCopyMode = False
'
End Sub