Excel help needed - creating a public variant

Please post any questions regarding the program here.

Moderator: 2020vision

Excel help needed - creating a public variant

Postby alrodopial » Fri Oct 09, 2009 8:06 pm

It must something really simple but I don't know how to declare/create variants, so:

I want to create a variant in the Worksheet_Change event and then use it in a module / macro.

The below code creates the variant but it does not keep it for the next macro.

Code: Select all
Public MyVar As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
   
    Dim MyVar As Variant
   
    Application.EnableEvents = False
   
    If Target.Columns.Count = 1 Then
        MyVar = "EEEEE"
        Call test1
    End If
   
    Application.EnableEvents = True
       
End Sub


and the module

Code: Select all
Public MyVar As Variant

Sub test1()
   
    Sheets("Sheet2").Range("A1") = MyVar
   
End Sub


Where I'm wrong?
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm

Postby throwmeadisc » Fri Oct 09, 2009 8:30 pm

Just put
Code: Select all
Public MyVar As Variant
in the top of the module and nowhere else. That also means don't Dim it in any Sub.

That's it.

Al :wink:
User avatar
throwmeadisc
 
Posts: 165
Joined: Fri Dec 14, 2007 11:06 am
Location: London, UK

Postby alrodopial » Fri Oct 09, 2009 8:50 pm

throwmeadisc wrote:Just put
Code: Select all
Public MyVar As Variant
in the top of the module and nowhere else. That also means don't Dim it in any Sub.

That's it.

Al :wink:


So simple when you know what you are doing.
Thanks mate
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 30 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.