Hi guys, me again.
This time I have a very simple question and it has to do with an IF statement. I come form web coding, so when it comes to IF statements in web coding the IF will validate true or false depending on what you are trying to confirm, pretty simple. I thought it was like this in VBA but apparently it's not exactly like this, seems like if the variable you are trying to validating does not even exists or can't be pulled up in any way, for some reason the code will stop at that point ... It would not go to the next "Else" as it would in web coding.
I am so new to VBA, so please be patient with me.
Maybe I'm missing something, or maybe I'm not using the IF statement as I should. Someone please bring some light to the matter.
I'll leave a snippet of my code here so you guys can see what I'm talking about. The code is working fine and it is doing exactly what I expect it to do, but the thing is that I really want to cover the situation in which someone would attempt to open a file that does not matches the criteria and, if that happens, I want to show an error message for the user to see it.
With this code, I'm just looking into a workbook for a specific sheet and validating the content inside a cell on that sheet. If that cell contains what is expected then I proceed executing my code, otherwise you should get a MsgBox. The problem comes when the sheet that I'm looking for does not exists, if this the case, the code stops with an internal error message and will not go to the end of the IF.
Here is the code:
I think that instead of looking for an specific sheet name (Which in my case could only be either "3" or "Validador") I could just do a loop trough all the sheets of the workbook and get the name of the first one that meets the criteria (Which in my case is to have the cell E3 = "Validador"). But I have no clue on how to do that, I was never good enough with loops. If someone could help me do that it would be even better than what I'm trying to do with the IF statements.
Bookmarks