lundi 18 novembre 2019

VBA: The use of GoTo for non errors

Just a quick question today, I am new to VBA and I am currently writing some code. In the code I use GoTo not for errors but just to write two different parts of functionality. For example the below:

Sub run_FetchTradeFilter()

    Dim EntrySelection As Range
    Set EntrySelection = Selection

    [EntireTradeQuery].Calculate
    If [CustomQuery] = True Then GoTo CaseCustomQuery Else GoTo CaseCustomList

CustomQuery:
    'fill
    'with
    'ccde A

CustomList:
    'fill
    'with
    'ccde B

    EntrySelection.Select

End Sub

My question is, should I be using GoTo if its not for an error. Or should I be using an if statement or should I be using a SwitchCase?

Aucun commentaire:

Enregistrer un commentaire