Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Stupid Excel VBA Question

  • 26-09-2011 08:23PM
    #1
    Registered Users, Registered Users 2 Posts: 604 ✭✭✭


    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, Paid Member Posts: 44,033 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, Registered Users 2 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, Registered Users 2 Posts: 604 ✭✭✭Gator


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


  • Moderators, Politics Moderators, Paid Member Posts: 44,033 Mod ✭✭✭✭Seth Brundle


    Are they form controls or ActiveX controls?


Advertisement