User forms

Dundee Lad

Active Member
Joined
Sep 6, 2003
Messages
311
I am new to using the userform and was looking for some help. I have data in some cells which i want the userform to pick up. I also have some cells which I want populated by the userform input. I have managed to create the userforms but this is as far as |i have got. searched on the board but did not find anything as basic as this. can you help me?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,808
Office Version
  1. 365
Platform
  1. Windows
Hi

Have you looked into Built-in forms for Excel data?

These are standard forms that can apply to data ranges. Go to Data -> Forms. Perhaps worth having a quick read on Excel help - it may well serve what you are after.

Regards
Jon
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,730
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
In the userform's Activate event (or Initialize event) you can use code like:
Code:
Me.Textbox1.Text = sheets("Sheet1").Range("A2").Value

and to reverse the process, just swap it round:
Code:
sheets("Sheet1").Range("A2").Value = Me.Textbox1.Text

You can also set the controlsource property of the controls on the userform to a range address, but I prefer to do it all through code.
HTH
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,730
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

Dundee Lad

Active Member
Joined
Sep 6, 2003
Messages
311

ADVERTISEMENT

Rorya, I have tried your code

Private Sub UserForm_Activate()
Sheets("Sheet2").Range("c7").Value = Me.TextBox62.Text
Sheets("Sheet2").Range("d7").Value = Me.TextBox61.Text
End Sub

but when I check sheet 2 my data is missing and there is no data in the userform?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,730
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Normally you would use the activate event to load data into your userform rather than the other way around because it is triggered when you show the userform. Your code is assigning the textbox values to the sheet ranges but the textboxes are probably blank at that point so you effectively clear the sheet ranges.
 

Dundee Lad

Active Member
Joined
Sep 6, 2003
Messages
311
Rorya, when I use the userform deactivate, it does not update the cells in excel? what am I doing wrong?

Code:
Private Sub UserForm_Deactivate()
Sheets("sheet3").Range("c4").Value = Me.TextBox62.Text
Sheets("sheet3").Range("d4").Value = Me.TextBox61.Text
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,130,167
Messages
5,640,535
Members
417,151
Latest member
ChickenTenderer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top