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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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