+ Reply to Thread
Results 1 to 2 of 2

Public Variables

  1. #1
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686

    Public Variables

    I define columns repeatedly in procedure after procedure

    I start by making the header cell of the column a Named Range such as Col_D_Hdr (generally it's more useful than that!)

    then
    Dim iMyCol As Integer
    iMyCol = Range("Col_D_Hdr").Column

    Is there a way to make this Public, defining them all when the workbook opens? Everyway I’ve tried failed.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,629
    You could:
    Insert a new module, declare the vars you want e.g.:
    Public iMyCol as Integer
    Public MyWS as WorkSheet
    Public MyRange as Range
    ...
    In the ThisWorkbook module initialize the vars
    iMyCol = Range("Col_D_Hdr").Column
    Set MyRange =Worksheets("Sheet2").Range("A?:??")
    Set MyWS = Worksheets("sheetname")
    ...
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1