vba to check a pivot table for a value

katekoz

Board Regular
Joined
Jan 20, 2020
Messages
91
Office Version
  1. 2016
Platform
  1. Windows
Hello! I have a UserValue input through an InputBox. I would like to check a little one-column pivot table to see if that value exists in the table. If it does, I will pop up a message. If not, continue with the macro. This is what I wrote, but it's (obviously) not working. At the bolded line, I get the error "Object doesn't support this property or method." I was thinking of turning the pivot table into a range and checking to see if the value exists in the range. Would that be a better way?? Any suggestions are appreciated!

UserValue = InputBox("Enter the username you'd like to add here:")

If ThisWorkbook.Sheets("Inputs").ListObject(1).Value = UserValue Then
ans = MsgBox("The user " & UserValue & " was already added and will be added as a duplicate. Would you like to continue adding?", vbYesNoCancel)
Select Case ans
Case vbYes
ThisWorkbook.Sheets("Inputs").Range("M2").Value = UserValue
Case vbNo
Exit Sub
Case vbCancel
Exit Sub
End Select
End If
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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