+ Reply to Thread
Results 1 to 8 of 8

Cant transfer variable using Public declaration

  1. #1
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Cant transfer variable using Public declaration

    I am trying to transfer a date from a User Form subroutine to a worksheet subroutine but cant seem to make it work. I have attached the workbook, the section of code I am having trouble with is in the userform and the PT Monthly Report-1 worksheet. The variable name is BSDT. I want it to be a date. Thanks.

    Dan

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

    Re: Cant transfer variable using Public declaration

    Dan

    Since you've declared BSDT in the userform module it isn't actually public.

    Public variables need to be declared in a standard module.

    Where/when are you trying to use BSDT, or more importantly the data selected, anyway?

    By the way, you could actually access the selected date elsewhere in the code just by using BillingDateTB.Text.

    That would only work if the userform was loaded of course, which it still will be after you've hidden it.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Cant transfer variable using Public declaration

    Hi Norie, thanks for your help.

    Would my worksheet SelectionChange be considered a standard module that I could declare a public variable?

    I tried to use BillingDateTB.Text to transfer the date to my 'PT Monthly Report-1' but I kept getting errors so I tried to use BSDT but I would prefer the first method. Do you have any suggestions?

    Thanks

    Dan

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

    Re: Cant transfer variable using Public declaration

    Dan

    A 'standard'q module is one created via Insert>Module.

    I actually missed out an important part in how to refer directly to the value on the form.

    For that to work you need to precede the control name with a reference to the userfom.

    For example, UserForm1.BillingDateTB.Value.

    You'll also need to convert the value to get a 'real' date, just as you are doing in the current code.

    By the way, it's usually better to refer to a value directly rather than using a public variable.

  5. #5
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Cant transfer variable using Public declaration

    How do I let the board know that the problem is SOLVED. Not sure how to do it.

    Dan

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

    Re: Cant transfer variable using Public declaration

    Select Thread Tools from the menu link above and mark this thread as SOLVED.

    PS How was it solved?

  7. #7
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Cant transfer variable using Public declaration

    I transferred the data using UserForm1.BillingDateTB.Value variable. It worked well. When I was first try to use it I forgot to put the UserForm in front of the variable. Thanks Again!

    Dan

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

    Re: Cant transfer variable using Public declaration

    Dan

    You never forgot the userform name, it was really me.

+ 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] Conditional public variable declaration
    By RedWing in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-13-2012, 11:16 AM
  2. Public Worksheet Declaration
    By wilro85 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2009, 08:08 PM
  3. Declaration of public variable - Question
    By Les Stout in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2005, 10:05 AM
  4. Public Declaration of a Worksheet Object?
    By Mech_Colin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2005, 01:03 PM
  5. [SOLVED] Public declaration
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2005, 07:06 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