Popup Message Box VBA

kabootar

New Member
Joined
Jan 15, 2019
Messages
10
Hi guys,

I have a code and I am not sure how to add a popup message box to appear;
One if it cant find workbook 1 and another to say copy completed once it has copied over.

Please any help would be appreciated!
Thank you

The code I have is:
Sub CopyData()

Dim Wb1 As Workbook, wb2 As Workbook, wB As Workbook

Dim rngToCopy As Range



For Each wB In Application.Workbooks

If Left(wB.Name, 7) = "NHE_000" Or Left(wB.Name, 6) = "Period" Then

Set Wb1 = wB

Exit For

End If

Next



If Not Wb1 Is Nothing Then '<~~ check if you actually found the needed workbook

Set wb2 = ThisWorkbook



Wb1.Sheets("QRA").Visible = True



wb2.Sheets("Current").Range("A4:AG30").Copy

Wb1.Sheets("QRA").Range("A4").PasteSpecial Paste:=xlPasteValues, Paste:=xlPasteFormats



Application.CutCopyMode = False



Wb1.Sheets("QRA").Visible = xlSheetHidden



End If

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try:
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim Wb1 As Workbook, wb2 As Workbook, wB As Workbook
    Dim rngToCopy As Range
    For Each wB In Application.Workbooks
        If Left(wB.Name, 7) = "NHE_000" Or Left(wB.Name, 6) = "Period" Then
            Set Wb1 = wB
            Exit For
        End If
    Next
    If Not Wb1 Is Nothing Then '<~~ check if you actually found the needed workbook
        Set wb2 = ThisWorkbook
        Wb1.Sheets("QRA").Visible = True
        wb2.Sheets("Current").Range("A4:AG30").Copy
        Wb1.Sheets("QRA").Range("A4").PasteSpecial Paste:=xlPasteValues, Paste:=xlPasteFormats
        Application.CutCopyMode = False
        Wb1.Sheets("QRA").Visible = xlSheetHidden
    Else
        MsgBox ("Needed workbook not found.")
        Exit Sub
    End If
    MsgBox ("Copy completed")
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,852
Messages
6,127,324
Members
449,374
Latest member
analystvar

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