views:

65

answers:

4

I have four sheets in a spreadsheet.

On each sheet there is a textbox.

When I type in the textbox on sheet1, I want the textboxes on sheet2, sheet3, and sheet4 to populate with the same value.

A: 

Do you want the other textboxes to be editable, or just always show the contents of the first? What happens to the other textboxes when a user edits the 2nd, 3rd, and so on (in the first case)? These questions will affect the solution... But if you just want the boxes to mimic the first, then use SheetName!CellAddress like this:

=WorksheetName!A1

Just substitute the name of the worksheet and the appropriate cell.

JYelton
For more information about referencing other worksheets, cells, programs, etc. in Excel, see this: http://office.microsoft.com/en-us/excel/HP051995141033.aspx
JYelton
I'm actually looking for something like =WorksheetName!textbox1althought I'm pretty sure that is incorrect.
Daniel
I'm sorry I am not familiar with using TextBoxes in Excel, however I found this site which might help (in answering your 'how to in code'); it's VBA: http://www.mrexcel.com/archive/Controls/4776.html
JYelton
A: 

Create a named range somewhere in your workbook, then type that name into the textbox linkedcell property.

That's not what I want. I want the cell to mimic what is in the textbox.
Daniel
By setting the linkedcell, that cell will take on the value of whatever you type in the texbox (and vice versa). Give it a try and let me know if it is not what you require.
If you want VBA code to accomplish this, let me know, but from your question it seems you might be able to accomplish this through standard Excel functionality.
Daniel, did you try this?
I don't want to use cell values. It should start in the textbox and cascade down to the other ones.
Daniel
It will cascade. You enter a value in the textbox which changes the value in the cell. The other textboxes pick up that value.
+1  A: 

Here's one way: Set the LinkedCell property of the first textbox to A1. Set the LinkedCell property of every other textbox to A1 of its own sheet. Then in sheets 2-4, cell A1, put

=Sheet1!A1

Now whatever you type in the textbox on Sheet1 will be in the textboxes on sheets 2-4. If you type anything in the textboxes in 2-4, you'll break the link. But from your question, it looks like you only want to type in the first one.

Here's another way.

Private Sub TextBox1_Change()

    Dim ws As Worksheet

    For Each ws In Me.Parent.Worksheets
        ws.OLEObjects("TextBox1").Object.Text = Me.TextBox1.Text
    Next ws

End Sub

Put that in the class module for the sheet. It assumes all your textboxes are named TextBox1. Whenever you change the one on Sheet1, the ones on the other sheet get changed.

Dick Kusleika
+2  A: 

Here is another way:

Create a module, and place this code there. This needs to be configured for your own specific textbox names and sheet names

Public Sub UpdateTextBoxes(str As String)

    Sheets("sheet1").TextBox1.Text = str
    Sheets("sheet2").TextBox1.Text = str
    Sheets("sheet3").TextBox1.Text = str
End Sub

Then for each textbox object you wish to replicate, use this for its change event (Sheet Class Module) (Change the paramaters to suite your needs)

Private Sub TextBox1_Change()
    UpdateTextBoxes Me.TextBox1.Text
End Sub

This way you can name your controls however you see fit, and you can update the text from any of the textboxes, and they will always be consistant.

Fink
You are my favorite person ever. Thanks!
Daniel