Is it possible for a user form to inherit editable text from a worksheet?

dbancroft

New Member
Joined
Jul 29, 2008
Messages
11
Hello all,

I'm still working on my design problem: allowing (very non-technical) users to edit Excel data in a format that doesn't look like a spreadsheet. A User Form the same size as the Excel screen might work, but only if User Forms can pick up data from the source worksheet, allow users to edit that data, and save it back to the source worksheet. Is that possible? And how would I do that? (I am NOT a programmer, just a tech writer being pressed into service!)

Thank you!!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
This is a very simple example, but if you create a UserForm with a TextBox and a CommandButton, then put this code behind it:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Rich (BB code):
<o:p></o:p>
Rich (BB code):
Rich (BB code):
Private Sub CommandButton1_Click()<o:p></o:p>
Range("A1") = TextBox1.Value<o:p></o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
Private Sub UserForm_Activate()<o:p></o:p>
TextBox1.Value = Range("A1")<o:p></o:p>
End Sub

<o:p> </o:p>
When the UserForm is opened, the TextBox will take on the value of cell A1 on the active sheet. When the CommandButton is pressed, it will send the current contents of the TextBox back to cell A1.
<o:p> </o:p>
However, what you are doing sounds like quite a big task, so you are going to need to become very much more familiar with the basic VBA concepts to achieve this properly I would think.
 
Upvote 0
Hey, that looks promising!

Is it possible to repeat that code so that multiple fields can appear in the same textbox? Oh... just looked again, no -- parsing it back out would be craziness (if not impossible).

So I need multiple textboxes, with this code in each (but edited to say Range("B1")=TextBox2.value, etc.)

I'll try it out and post a "Solved" message if it works.

Thanks very much,

Deb.
 
Upvote 0
Hi Deb. You may also wish to look into the ControlSource property. This property links a range to a control - such as a textbox. If data is changed in the textbox, it is automatically reflected in the range - visa versa...
 
Upvote 0
OK, really dumb question: I've created a user form but it doesn't open when I open the Excel file. I assume I have to tell it to open (duh) but not sure how.
 
Upvote 0
And Tom -- does ControlSource do something different from Lewiy's code below? Or is it just a more straightforward way to do it?
 
Upvote 0
You do indeed need to “tell” the UserForm to open. You can do this with the code:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Rich (BB code):
<o:p></o:p>
Rich (BB code):
Rich (BB code):
UserForm1.Show<o:p></o:p>
<o:p></o:p>
<o:p> </o:p>
You will need to decide what will trigger the form to open. You could put a CommandButton on a worksheet with that code behind it, or you could use an “Event” such as Workbook_Open() or Worksheet_Activate() to trigger the code.<o:p></o:p>
<o:p> </o:p>
The ControlSource property will link the TextBox directly with a particular cell or range in a worksheet. Depending on your actual intended use of the UserForm, this may or may not be the best option. It would be useful if you have a 1:1 relationship between the TextBox and a particular cell, i.e. the one TextBox will ALWAYS affect and be affected by the same cell.<o:p></o:p>
 
Upvote 0
So:

Workbook_Open(UserForm1.Show)

?

And I assume that's on the Worksheet?


Another question: The Text Box on the User Form opens with existing code:
Private Sub TextBox1_Change()

End Sub

Do I want to keep that & insert my code between?
 
Upvote 0
To use the Workbook_Open() Event, you need to place the code in the ThisWorkbook module (which can be opened by right clicking on the excel logo in the top left of Excel next to the file menu and clicking View Code). You would want something like this:
Rich (BB code):
Rich (BB code):
Rich (BB code):
Private Sub Workbook_Open()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
UserForm1.Show<o:p></o:p>
End Sub

<o:p> </o:p>
Re the textbox:
Every object has a number of events associated with it that you can choose from. The code:
Rich (BB code):
Rich (BB code):
Rich (BB code):
Private Sub TextBox1_Change()

End Sub<o:p></o:p>
<o:p></o:p>
<o:p> </o:p>
Is just the default event. If you wanted something to happen when the textbox value changes then you would write the code between these lines. If not then you can leave it there as it is, or delete it.<o:p></o:p>
<o:p> </o:p>
You will notice two drop down menus at the top of the VB Editor. The left one will allow you to select an object (i.e. UserForm, TextBox, CommandButton, etc.) and the right one allows you to select the event that you want to use based on the selected object. Once you select an event, it will place the first and last lines (similar to what you had for the text box) into the module. All code written that you want to be invoked by that event, would be written between these two lines.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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
Back
Top