Variable Declaring. Textbox On Userform To Show Value Of A Cell

  • Hi


    Users select a row number which then opens up a Userform.


    Comboboxes and Textboxes on this Userform are then populated with coloumn values (dependant on the row initially selected)


    If the row number was the same each time I could accomplish this by the following.


    Code
    Private Sub TextBox1_Enter()
    TextBox1.Value = Range("a1")
    End Sub


    but as its a variable I'm trying the following (which I think should work)


    Code
    Private Sub TextBox1_Enter()
    TextBox1.Value = Range("a" & edi & "")
    End Sub


    I think I need to declare the variable 'edi' as Public. If so where should this be? I've tried 'Genereal Declaration'


    ie


    Code
    Public edi


    If I am barking up the wrong tree can someone please help?


    Thanks

  • Re: Variable Declaring. Textbox On Userform To Show Value Of A Cell


    If you use a public variable make sure it is declared in a standard code module and not in the code module of either the userform or sheet.


    You maybe able to make use of the ActiveCell object instead of passing variables.
    Or you could add a public variable to your userform that you set prior to showing the userform

    [h4]Cheers
    Andy
    [/h4]

  • Re: Variable Declaring. Textbox On Userform To Show Value Of A Cell


    The article on writing code in the VBA section might help you. Not really sure why you are using the TextBox_Enter procedure. I would use the UserForm_Activate and load all the TextBoxes


    Code
    Dim r as Long
    Private Sub TextBox1_Enter() 
    r=ActiveCell.Row
        TextBox1.Value = Cells(r,1)
    End Sub
  • Re: Variable Declaring. Textbox On Userform To Show Value Of A Cell


    Andy


    I'm sorry I'm a little confused.


    I've placed


    Code
    public edi as range


    in Module1 under modules, is this correct?

  • Re: Variable Declaring. Textbox On Userform To Show Value Of A Cell


    ha! disregard, sorted. I had forgotten about another instance where I had declared it :)


    Thanks to both for you time.


    Regards

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!