Error handeler to bring up MsgBox

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi there,

I need some code to bring up an msgbox on error:

Below is the section of code:

if the Name entered into the Inputbox does not match any of the items in the pivot table field I need a message box to appear, and the exit sub.

Code:
Range("C7") = InputBox("What Month would you like to extract? i.e. 2011/01/01 ", "Type in Month")
Set V_R = Range("C8")
Set Out_Name = Range("C6")
Set Month_Name = Range("C7")
With Sheets("List").PivotTables("PivotTable2").PivotFields("MONTH")
        .PivotItems(Month_Name.Value).Visible = True
        For Each Pi In .PivotItems
           If Pi.Name <> Month_Name.Value Then Pi.Visible = False

         Next Pi
    End With
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
...
    [COLOR="Blue"]If[/COLOR] Pi.Name <> Month_Name.Value [COLOR="Blue"]Then[/COLOR]
        Pi.Visible = [COLOR="Blue"]False[/COLOR]
        MsgBox "Oops, Error occured!"
        [COLOR="Blue"]Exit[/COLOR] [COLOR="Blue"]Sub[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
...
 
Upvote 0
I still get the error, because the name can be entered into the inputbox, but it may not exsist on the PT field list.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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