Results 1 to 10 of 10

Thread: Assign worksheet to Global variable. Possible? or Worth it?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    VBAX Newbie
    Joined
    Dec 2022
    Posts
    4
    Location
    AHHHH.. got it! Thanks. I am just having trouble wrapping my head around using predefined variables with other modules. Do I need to reference the variables in another module? as below?

    Option Explicit
    
    Dim WB1 As Workbook
    Dim SH1 As Worksheet
    Dim SH2 As Worksheet
    
    Sub SelectPages()
        Set WB1 = ThisWorkbook
        Set SH1 = WB1.Worksheets("Sheet1")
        Set SH2 = WB1.Worksheets("Sheet2")
        SH1.Select
        SH2.Select
    End Sub                         
    
    Sub OtherPages(WB1, SH1, SH2)
        WB1.DoSomething
        SH1.JumpRope
        SH2.EctEctEct
    End Sub

    Or do I even need the "(WB1, SH1, SH2)" on the OtherPages?
    Last edited by Aussiebear; 10-03-2024 at 01:00 PM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •