+ Reply to Thread
Results 1 to 3 of 3

Variable not available

  1. #1
    Registered User
    Join Date
    05-14-2008
    Posts
    27

    Variable not available

    Hello,

    I am having a little bit problem with the way Excel works with VB.

    I have a button in my Worksheet that calls a method which defines:

    Dim data As DataType
    data.name = "name"
    data.type = "type"
    ...

    Then on Worksheet_SelectionChange I call a function which should use "data" variable and the row and column of the cell clicked.

    The "data" variable is not available in Worksheet_SelectionChange.

    How can I solve this?
    ,
    Miguel
    Should I define the data variable in some other Worksheet event?

    Thank You



    Private Sub Worksheet_SelectionChange(ByVal Target As range)

  2. #2
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,230
    Its a matter of scope. Placed at the top of a module, before any subs,
    Please Login or Register  to view this content.
    will make dataVariable availiable to all routine that module, but not in others. To make a variable avaliable to all modules the Public keyword should be used
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    05-14-2008
    Posts
    27

    Question

    Thank You! It worked.

+ 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