How do I handle the error: “No item of this name exists in the PivotTable report.”

RichLN

New Member
Joined
Dec 16, 2015
Messages
5
So I have a PivotTable being modified via a commandbox inside of a userform. If the user types in a name that isn't in the list, I get the error:
No item of this name exists in the PivotTable report. Rename Name1 to Name2? where <code style="color: rgb(34, 36, 38); margin: 0px; padding: 1px 5px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Name1</code> is a person on the list and <code style="color: rgb(34, 36, 38); margin: 0px; padding: 1px 5px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Name2</code> is a person not on the list.
I actually get this error like 5 times b/c of the number of PivotTables my commandbox modifies.
I tried the following:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">OnErrorResumeNext

</code>I was hoping that would simply "skip over" the issue. Nope, that didn't work out haha.
Though ideally I would like to create a custom error message that pops up only one time (instead of 5 times) and tells the user to enter a name from their department/shift. The list (that my commandbox uses) overall has everyone from every shift from every department, but not all people have data in the PivotTable and so just b/c they are on the list my commandbox users, they are not necessarily in the PivotTable. I know that's confusing, but I have to have it that way b/c the same interface is being used by all shifts. I do not have access to the list of people within departments, shifts, etc. I only have a master list of everyone, so that's why my commandbox has to use that.
I'm still "new" to VBA, but I am not new to error handling in general. I know how I would handle this in Java, but not in VBA.

This is the part of code, which fails:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Range("D2").Select
ActiveCell
.Value = frmInd_Productivity_TrackerPS.ComboBox1.Value
ActiveSheet
.Range("B1").Select
ActiveCell
.Value = Range("F2").Value

</code>
My main problem is that I don't know how to get it to "skip" that error and actually go to the next error? Can you tell me how to do that? In Java, the Try/Catch block automatically goes to the next level after handling the error. I can't get VBA to just "toss out" the error and continue running.

I have 5 PivotTables in total, all of which get modified by the commandbox. So each one of them throws up the error, giving me 5 errors in a row that ask me to rename a person on the pivottable to the name of the person that isn't. B1 is my pivottable filter box. I have to modify the value from the combobox, which is the value that "F2" winds up as. In other words, "F2" is my finished product that is "copied" to the pivottable filter box (I know you can't actually "copy" it there, its just setting the value equal to "F2").


 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I tried adding the following at the very top of my coding, but this just makes the error box pop up even when the person is in the pivottable and the thing works correctly!?! No clue why it's popping up the MessageBox when there is no error!?!

On Error GoTo ErrHandler:


ErrHandler:
' error handling code
Resume ErrMessage:


ErrMessage:
MsgBox "Name not found in this Department. Please Enter a New Name from this Department."
Exit Sub
 
Upvote 0
I couldn't find a way to do what I wanted. I did find a solution though.


Problem solved (band-aid applied):


I made a new sheet that called the info from the combobox. It converted it and then used it to check whether that info appeared on my pivottable using a loop. Then I assigned a variable a result based on whether it found it (stored in a new variable). If the result was 1, an "If" statement executes the entire block of my program. If the result was 0 (meaning it didn't find the name on the pivottable), then it pops up a message saying to change the name and exits the sub. Hope this helps someone in the future.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,343
Members
449,155
Latest member
ravioli44

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