• Declarations

    Author
    Topic
    #460011

    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets(“x”)
    Set ws2 = Worksheets(“y”)

    I want to use the above in all of the below, Can I set these once instead of individually?

    Public Sub UserForm_Activate()
    Public Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Public Sub SearchButton1_Click()

    Viewing 2 reply threads
    Author
    Replies
    • #1161622

      You could declare the variables as public at the top of a standard module, and set their value in the Workbook_Open event procedure in the ThisWorkbook module.
      But you’d have to be very careful: if an unhandled error occurred, the variables would lose their values.

    • #1161624

      I’ll stich with the safer option, less hassle. Thanks

    • #1161785

      You could make ws1 and ws2 functions rather than variables.

    Viewing 2 reply threads
    Reply To: Declarations

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: