mardi 13 août 2019

Is there a Elseif limitation?

I am trying to write a code which will call different subtasks depending and a choice from a spreadsheet (and as it is using a different file as weel, making sure the right file has been chosen). We previously had that for 7 subs but I wanted to add a new one. On meeting the conditions for the 8th one I always went to the errhandler line (else) and it never ran the Sub8. I checked the conditions were met using some MsgBox to make sure of it.

Is there some limitation I am missing? Is there something obvious I am missing?

Thanks for your help!

I used some message box to see where it was blocking but it seems it just won't read the last elseif I added. I tried to change some of the order but it did not work. I change the option 9 for 2 and it worked as expected so I am kind of lost here.

If you have any ideas that would be appreciated.

If run_wb.Sheets(1).Range("Range") = "Option1" And Raw_wb.Names("template_type").RefersToRange = "suboption1" Then Call Sub 1

ElseIf run_wb.Sheets(1).Range("Range") = " Option2" And Raw_wb.Names("template_type").RefersToRange = " suboption2" Then Call Sub 2

ElseIf run_wb.Sheets(1).Range("Range") = " Option3" And Raw_wb.Names("template_type").RefersToRange = " suboption3" Then Call Sub3

ElseIf run_wb.Sheets(1).Range("Range") = " Option4" And Raw_wb.Names("template_type").RefersToRange = " suboption4" Then Call Sub4

ElseIf run_wb.Sheets(1).Range("Range") = " Option5" And Raw_wb.Names("template_type").RefersToRange = " suboption5" Then Call Sub5

ElseIf run_wb.Sheets(1).Range("Range") = " Option6" And Raw_wb.Names("template_type").RefersToRange = " suboption6" Then Call Sub6

ElseIf run_wb.Sheets(1).Range("Range") = " Option7" And Raw_wb.Names("template_type").RefersToRange = " suboption7" Then Call Sub6

ElseIf run_wb.Sheets(1).Range("Range") = " Option8" And Raw_wb.Names("template_type").RefersToRange = "suoption8" Then Call Sub7

ElseIf run_wb.Sheets(1).Range("Range") = " Option9" And Raw_wb.Names("template_type").RefersToRange = "suboption9" Then 'Call Sub8 MsgBox ("ok")

Else errhandler: MsgBox "The wrong template has been selected or this template cannot be used for data import. Please contact a system admin." Raw_wb.Close End If

Aucun commentaire:

Enregistrer un commentaire