Text Box ControlSource issues

ultrawat

New Member
Joined
Nov 7, 2005
Messages
47
I have a spreadsheet which has pop-up user form, with text boxes which link to a cell on another sheet in the workbook.

ie the user form pops up, I enter a number in the text box field, and this number appears in the linked cell in a separate worksheet in the workbook.

My problem comes when I save the workbook to a different name. The ControlSource area in the properties fields keeps the cell reference for the 'old' filename.....??

Can anyone help with how this ControlSource link changes to the new file name??

Any help would be really appreciated..... :confused:
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I can reproduce that behaviour only if both workbooks are open and the original workbook is the ActiveWorkbook. Is that the case for you?

I tend to avoid the ControlSource property because it can be problematical. I update the Control in code when the UserForm is shown and the target cell when the value in the Control changes.
 

ultrawat

New Member
Joined
Nov 7, 2005
Messages
47
Thanks Andrew

I should have said that the process is Save as......

I like the idea of code instead of using ControlSource.

Can you give me a sample code for this process?

Really appreciate your help.....
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Sample code:

Code:
Private Sub UserForm_Initialize()
    TextBox1.Value = Worksheets("Sheet1").Range("A1").Value
End Sub

Private Sub TextBox1_Change()
    Worksheets("Sheet1").Range("A1").Value = TextBox1.Value
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,820
Messages
5,574,511
Members
412,599
Latest member
Schu94
Top