How to take over the value of a userform-controle to a cell

  • Thread starter Thread starter Filips Benoit
  • Start date Start date
F

Filips Benoit

Dear All,

I'm new at Excel-programming!

I want to show a form to input several lines of text in a cell.
I can NOT enlarge the cell.
I created a userform that shows when the cell has the focus.
BUT how do i take the value from the cell to the form-controle and back.
When opening the formcontrole must show the cell-value.
Closing the form the cell must show the form-controle-value.


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
If Target.Column = 9 And Target.Row > 6 Then
Frm_NOTA.Show
ActiveCell.Value = ........?????
End If
End Sub

Thanks,

Filip
 
In the form code you need to put an initialise eveny to 'copy' the
activecell into the form control (in this case called TextBox1), then when
the user closes the form (presses cross in top right) the value is passed
back to the active cell and the form closes.

Put the following code into the form by going to VBA editor (Alt-F11) and
select FORM from the project explorer and right- click then choose VIEW code
and paste the folllowing.....

Private Sub UserForm_Initialize()
TextBox1.Value = ActiveCell.Value
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ActiveCell.Value = TextBox1.Value
Unload Me
End Sub
 
Thanks³

Nigel said:
In the form code you need to put an initialise eveny to 'copy' the
activecell into the form control (in this case called TextBox1), then when
the user closes the form (presses cross in top right) the value is passed
back to the active cell and the form closes.

Put the following code into the form by going to VBA editor (Alt-F11) and
select FORM from the project explorer and right- click then choose VIEW code
and paste the folllowing.....

Private Sub UserForm_Initialize()
TextBox1.Value = ActiveCell.Value
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ActiveCell.Value = TextBox1.Value
Unload Me
End Sub
 
Another way

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
If Target.Column = 9 And Target.Row > 6 Then
Frm_NOTA.Load
Textbox1.Vakue = Target.Value
Frm_NotA.Show
Target.Value = Textbox1.Text
Un load Frm_NotA.Show
End If
End Sub

Just make sure that you hide the form in the form code, not unload it.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top