Count Rows Copied

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
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Immediately before End If put a counter : c=c+1

Then :
MsgBox c & " rows of data were copied to " & tgtPath
 
Upvote 0
Solution
Thank you for the reply footoo. The only 'End If' I have in this code is where I test to see if the file is already open. Apologies if I am misunderstanding.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top