Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Stupid Excel VBA Question

Options
  • 26-09-2011 8:23pm
    #1
    Registered Users Posts: 601 ✭✭✭


    Really cannot believe I cannot get this work,

    two text boxes on two seperate sheets, after a click event I want textbox 1 to write to textbox one on another sheet

    Worksheets("sheet1").TextBox1.Value = Worksheets("sheet2").TextBox1

    the value just seems dissapear, I have removed the .value and .text but nothing, the value of textbox just dissapears.

    these are embedded text boxes and not on a form which I have never tried before,

    any ideas??


Comments

  • Moderators, Politics Moderators Posts: 39,602 Mod ✭✭✭✭Seth Brundle


    Set breakpoints within your code (press F9 on one of the lines) and then step through your code (F8) - this should show you where its breaking.

    However, is there an event on both text boxes?
    If so then add something like Application.EnableEvents = False
    and turn it back on (by setting it to True (and same again in your error handling code).

    However, the following works fine for me:
    Private Sub CommandButton1_Click()
    On Error GoTo ThePub
        Me.TextBox1.Value = Sheets("Sheet2").TextBox1.Value
        Exit Sub
    ThePub:
        MsgBox Err.Description, vbExclamation, "My App"
    End Sub
    
    (bearing in mind the control names are the defaults.


  • Registered Users Posts: 898 ✭✭✭OREGATO


    By the looks of it, you're missing '.Value' at the end of the line.

    Worksheets("sheet1").TextBox1.Value = Worksheets("sheet2").TextBox1

    As shown in the post by kbannon, he has:

    Me.TextBox1.Value = Sheets("Sheet2").TextBox1.Value
    HTH


  • Registered Users Posts: 601 ✭✭✭Gator


    Still couldnt get it to work,very strange, i just wrote the values to cells instead, cheers


  • Moderators, Politics Moderators Posts: 39,602 Mod ✭✭✭✭Seth Brundle


    Are they form controls or ActiveX controls?


Advertisement