+ Reply to Thread
Results 1 to 5 of 5

UserForm Labels Drawn from Cell in Sheet

  1. #1
    Registered User
    Join Date
    12-28-2015
    Location
    Portland, OR, USA
    MS-Off Ver
    365
    Posts
    3

    UserForm Labels Drawn from Cell in Sheet

    This one is driving me crazy, so any help would be very much appreciated.

    I have a template that allows the user to create a worksheet for tracking a series of bond investments. When they want to add a new bond, they click a command button that calls a userform (NewBondUserForm) for entering the details of the bond - this then calculates the # of bonds to buy and asks if they'd like to add it to the holdings. If they click yes, it calls a second userform (BondAddUserForm) that asks how many bonds they will actually purchase and then adds them into the holdings.

    I'm trying to get this second userform's labels to show the max number of bonds they CAN add as well as the issuer. Both of these data points are held in cells on the activesheet. But no matter what I do the two labels are showing up as blank.

    Here's the portion of the code that calls the second userform from within the first:


    Please Login or Register  to view this content.
    answer = MsgBox("You can purchase up to " & BondNum & " of these Bonds. Add to Ladder?", vbYesNoCancel, "Results")

    Select Case answer

    Case 7
    Unload NewBondUserForm
    Exit Sub

    Case 6
    Call BondAddUserForm_Initialize

    Case MsgBoxResult.Cancel
    Unload NewBondUserForm
    Exit Sub

    End Select
    Please Login or Register  to view this content.
    And then the code for the second userform's initialize, also stored within the first userform's code:

    Please Login or Register  to view this content.
    Private Sub BondAddUserForm_Initialize()

    '***********************Open BondAddUserForm to Finalize Data for Bond Purchase***********************************************

    Dim IssuerCap, BondNum As Variant, WS As Worksheet

    Set WS = ActiveSheet

    IssuerCap = WS.Range("O2")
    BondNums = WS.Range("O7")

    BondAddUserForm.Show

    'Remind user of issuer and suggested purchase number

    BondAddUserForm.Label1.Caption = "You are adding a " & IssuerCap & " bond to the ladder"
    BondAddUserForm.Label2.Caption = "You can add up to " & BondNum & " bonds to the ladder"

    End Sub
    Please Login or Register  to view this content.
    Thanks in advance for any advice!!!!

  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: UserForm Labels Drawn from Cell in Sheet

    Have you stepped through the code with F8 to see what's actually happening?

    By the way, couldn't you also display the # of bonds and Issuer on the first userform as well as in cells?

    Then when you show the second userform you can populate the labels on it from the first userform.

    PS Instead of calling the Initialize event you should just use this to show the second userform.
    Please Login or Register  to view this content.
    PPS Can you add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-28-2015
    Location
    Portland, OR, USA
    MS-Off Ver
    365
    Posts
    3

    Re: UserForm Labels Drawn from Cell in Sheet

    Thanks for the input - I used F8 (unaware of that function, super-useful) and cleaned up a bunch of the code on the first userform as a result. I made all the variables I was storing in cells on the activesheet public and still set them via the first userform.

    The reason I was using the second userform is twofold: First, the data on the first userform needs to be run through some calculations to recommend a number of bonds to buy (this may be more or less than the target value established earlier in the process depending on the bond price). Second, if the user is targeting, say, $10K in bonds for 2022 maturity, but there are only $5K available to purchase, I need to be able to get that input from the user and adjust the spreadsheet accordingly.

    The first userform code ends like this (using .show as you suggest):

    Please Login or Register  to view this content.
    And then this is the code for the second userform:

    Please Login or Register  to view this content.
    Still not getting the captions to pop up. All the variables then push through correctly to the calculations that are made when clicking "OK" on the BondAddUserForm. The only issue is the lack of captions showing up on the BondAddUserForm...

    Many thanks again.

  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: UserForm Labels Drawn from Cell in Sheet

    A userform's Initialize event is always called UserForm_Initialize, it's never called formname_Initialize and there's definitely no parameters passed to it.

    So in the original code instead of this,
    Please Login or Register  to view this content.
    you should have this.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-28-2015
    Location
    Portland, OR, USA
    MS-Off Ver
    365
    Posts
    3

    Re: UserForm Labels Drawn from Cell in Sheet

    Awesome! That did it. Thanks so much for the help - been driving me crazy.

    -Patrick

+ 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] Userform labels to repeat/autofill exactly into other labels on the same userform
    By indub in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2015, 02:18 PM
  2. Excel Auto Due Drawn Sheet Problem
    By AVG123 in forum Excel General
    Replies: 1
    Last Post: 09-03-2015, 01:47 AM
  3. Excel Due Drawn Sheet Problem
    By AVG123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2015, 03:08 AM
  4. Excel Auto Due Drawn Sheet Problem
    By AVG123 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-27-2015, 02:45 AM
  5. [SOLVED] VBA Userform: Inserting cell data into useform labels
    By B Eccles-Williams in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2014, 10:30 AM
  6. [SOLVED] Add Sheet Names to Userform Labels
    By zimboo in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 03-21-2013, 03:26 PM
  7. [SOLVED] Change values of labels in a userform through another userform
    By Zhennie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2009, 05:34 AM

Tags for this Thread

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