How to handle a VBA error pop up

I am using the following script to unlock the sheets in a workbook:

Sub WorksheetsUnlock(sheetName1, sheetName2)
Worksheets(sheetName1).Unprotect “ABC”
Worksheets(sheetName2).Unprotect “ABC”

End Sub

I want to handle a situation where one or both sheets are not found. I am getting a pop up with the error. How to get this error in a variable?

image

Hy @papulepooja,

I am expert in Excel VBA, could you share your entire project folder with me so I can take a look at your VBA Code?

This error means that something that was supposed to be found was not found

1 Like

@papulepooja

Hi,

Application.DisplayAlerts = False

Try that, hope it helps

Thanks

Hy @ksrinu070184,

Unfortunatly that won’t work on this.
This VBA Property is to supress a message, for example, confirmation message before deleting a sheet. ok?

Hi @William_Blech_Sister,
Thanks for you reply!
Here is a sample test code for which I am getting the same error. The VBA accepts 2 worksheets names but the excel has only one. I want to catch this error without having to deal with the message box.
TestVBA.zip (23.6 KB)

Hy @papulepooja,

I figure out your problem

Your code takes input of two sheet names

image

But your file has only one

image

That explain your error.

I recomend you to adjust your code, for your VBA Function to take only one parameter at a time.

If you like my answer please like it and mark as solved :slight_smile:
Regards

1 Like

Hi @William_Blech_Sister,
I deleted the sheet to test an error in such a case where one or both the sheetnames are not found. I want to return an error in some variable.

Thanks!

1 Like

@papulepooja

Glad I could help you!!

Please dont forget to mark my answer as solution.

image

Thanks