Counter Msgbox

meakashgfx

New Member
Joined
Dec 9, 2014
Messages
33
Hi,

I have loop that copy cells from excel files into master file. Instead of showing Msgbox I want to count them how many files are show missing.

here is the code I have:

Code:
Private Sub StartCopy_Click()


Dim MyFile As String
Dim erow
Dim Filepath As String
Dim FindString As String
Dim RangeObj As Range


    Filepath = "C:\Excel-Mastermind\1\"
    MyFile = Dir(Filepath)
    Do While Len(MyFile) > 0
        If MyFile = "Master.xlsm" Then Exit Sub
        Workbooks.Open Filepath & MyFile
        Range("B2:D18").Copy
        FindString = Cells(2, "A").Value
        ActiveWorkbook.Close False
        Set RangeObj = Cells.Find(What:=FindString, After:=Cells(1), _
                                  LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
                                  SearchDirection:=xlNext, MatchCase:=False)
        If RangeObj Is Nothing Then
            MsgBox "Not Found", vbExclamation
        Else
            RangeObj.Offset(rowOffset:=3, columnOffset:=0).PasteSpecial
        End If
        MyFile = Dir
    Loop
    MsgBox "Done!"
End Sub

Thanks in advance!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
not tested but:

Code:
Private Sub StartCopy_Click()




Dim MyFile As String
Dim erow
Dim Filepath As String
Dim FindString As String
Dim RangeObj As Range
Dim lngCount As Long


    lngCount = 0
    Filepath = "C:\Excel-Mastermind\1\"
    MyFile = Dir(Filepath)
    Do While Len(MyFile) > 0
        If MyFile = "Master.xlsm" Then Exit Sub
        Workbooks.Open Filepath & MyFile
        Range("B2:D18").Copy
        FindString = Cells(2, "A").Value
        ActiveWorkbook.Close False
        Set RangeObj = Cells.Find(What:=FindString, After:=Cells(1), _
                                  LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
                                  SearchDirection:=xlNext, MatchCase:=False)
        If RangeObj Is Nothing Then
            'MsgBox "Not Found", vbExclamation
            lngCount = lngCount + 1
        Else
            RangeObj.Offset(rowOffset:=3, columnOffset:=0).PasteSpecial
        End If
        MyFile = Dir
    Loop
    MsgBox "Done!" & vbCrLf & "Missing files: " & lngCount
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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