larryjfoster
New Member
- Joined
- Jul 19, 2017
- Messages
- 20
I have the below code which works great. After searching this and other forums I can't find a suitable code that will allow me to store the number of rows copied to display in a message box. Thank you for your help!
Code:
Dim tgtWB As Workbook
Dim tgtPath As String
Dim ws As Worksheet
Dim lr As Long
Set ws = Application.Sheets(1)
lr = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
tgtPath = "C:\FlderA\FlderB\tgtreport.xlsx"
Set tgtWB = Workbooks.Open(tgtPath)
'Check to see if file is already open
If tgtWB.ReadOnly Then
ActiveWorkbook.Close
MsgBox "Cannot update Daily Language Translation EXCEL letter report, another user currently has file open. Please try again later."
Exit Sub
End If
ws.Activate
For i = 2 To lr
If (Cells(i, 31) <> "A" And Cells(i, 31) <> "B" And Cells(i, 31) <> "C" And Cells(i, 31) <> "") Or _
((Cells(i, 30) <> "A" And Cells(i, 30) <> "C" And Cells(i, 30) <> "") And Cells(i, 31) <> "A") Then
Range(Cells(i, 1), Cells(i, 35)).Copy
tgtWB.Activate
Range("A12000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
ws.Activate
End If
Next i
tgtWB.Close SaveChanges:=True
ws.Activate
'MsgBox copiedRows & " rows of data were copied to " & tgtPath
End Sub