+ Reply to Thread
Results 1 to 4 of 4

Using 'Target' as a public variable

Hybrid View

  1. #1
    Registered User
    Join Date
    01-07-2004
    Location
    Manchester UK
    MS-Off Ver
    Office 2010
    Posts
    73

    Using 'Target' as a public variable

    Hi,

    I have a worksheet and in column D i have several amounts, all numbers. I'm using the on double click worksheet event to trigger a macro when one of these cells is the 'Target'. I want the value of that cell to be available as public variable, so I can use it in modules called by the on double click event.

    I've tried declaring it as Public in a normal module but I couldn't get it work.

    thanks in advance for any help.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using 'Target' as a public variable

    Public Target1 as range
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    set Target1 =Target
    ...............
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Using 'Target' as a public variable

    Why not pass Target as an argument to the other subs?
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        Call AnotherSub(Target)
    End Sub
    
    Sub AnotherSub(Target As Range)
    
    End Sub
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    01-07-2004
    Location
    Manchester UK
    MS-Off Ver
    Office 2010
    Posts
    73

    Re: Using 'Target' as a public variable

    Went with nories solution, didn't now that was possible, still a noob!! Thanks for the help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro can't see a public variable
    By etminasm in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-27-2014, 04:21 AM
  2. Define a public variable
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2013, 06:48 AM
  3. Public Variable value
    By nfpaccounting in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2011, 02:34 PM
  4. Public Variable
    By Digitborn.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2007, 03:54 PM
  5. [SOLVED] Public variable
    By Jack in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 03-18-2006, 05:40 PM

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