Hi
MS 365 on Win10
I am wanting to be able to save data entered in a userform for later additions or editing before posting to final spreadsheet
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Save user form for later editing
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Save user form for later editing
- This topic has 25 replies, 4 voices, and was last updated 8 years, 11 months ago.
AuthorTopicViewing 16 reply threadsAuthorReplies-
RetiredGeek
AskWoody_MVPJune 13, 2016 at 9:01 pm #1567483Phil,
A little more information please.
-
[*]I take it this is a partial record?
[*]Do you want the record saved automatically (if it is a partial and user exits the form)?
[*]Do you want a button on the userform to allow the user to select if the record should be saved for later?
[*]Do you want to save the record in the workbook or to an external file?
[*]Is this a multiple user workbook (this would probably necessitate saving to an external file or at least tagging the record with the responsible user’s ID.
[*]Could you post an example workbook with the userform and some sample data?HTH :cheers:
-
Bonriki
AskWoody LoungerJune 13, 2016 at 9:16 pm #1567485RG hi again
The file is set as an xltm so the save function would be xlsx but of course that will not allow further editing. The intention is that staff generate the report monthly and send to Commercial Manager for compilation in to consolidated report.-
[*]Yes a partial record
[*]Yes save automatically
[*]Have a Save for Edit button
[*]In the workbook is OK or maybe an external file
[*]Single user workbook -
RetiredGeek
AskWoody_MVPJune 13, 2016 at 9:45 pm #1567488Phil,
You already have the button you just need to program it. You even have most of the code in the CmdBtnOK_Click code it just needs to be copied to the CmdBtnSave_Click (the part where you save the data from the form) event and modified to save to a temp sheet (I’d have it create a new sheet for this function).
Then in the Workbook_Open event I’d check for this temp sheet and if it exists automatically display the form and load it with the values from the temp worksheet and then delete the temp sheet. This should keep things nice and tidy.
If you want to make your code easier to maintain you could make a subroutine out of the part that saves the data and then just call the subroutine with the sheet to which the data should be saved! One block of code to maintain then if you add or delete fields from the form.
If you have problems implementing this post back but from the looks of it you should be able to handle it now that you know what to do.
HTH :cheers:
-
Bonriki
AskWoody LoungerJune 14, 2016 at 3:46 pm #1567541Phil,
Then in the Workbook_Open event I’d check for this temp sheet and if it exists automatically display the form and load it with the values from the temp worksheet and then delete the temp sheet. This should keep things nice and tidy.
If you want to make your code easier to maintain you could make a subroutine out of the part that saves the data and then just call the subroutine with the sheet to which the data should be saved! One block of code to maintain then if you add or delete fields from the form.
HTH :cheers:
RG
I am having trouble with this bit, checking the sheet exists and then populating the form with the existing data.Your idea of a separate module looks good too.
-
-
RetiredGeek
AskWoody_MVPJune 14, 2016 at 4:37 pm #1567546Phil,
Here’s the skeleton for the the procedure:
Code:Option Explicit Sub Workbook_Open() Dim wksTemp As Worksheet On Error Resume Next Set wksTemp = ActiveWorkbook.Worksheets("PartRecord") On Error GoTo 0 If (wksTemp Is Nothing) Then '*** No temp record found *** MsgBox "No Temp Record was found", _ vbOKOnly + vbInformation, "Testing" Else '*** Load Temp Record into form and display *** MsgBox "Temp Record was found", _ vbOKOnly + vbInformation, "Testing" '*** Code to load & display form goes here *** Sheet1.Select '*** Substitute your main sheet for Sheet1! Application.DisplayAlerts = False '*** Hide deletion confirmation dialog *** wksTemp.Delete Application.DisplayAlerts = True '*** Restore confirmation dialogs *** End If End Sub 'Workbook_Open
This code gets placed in the ThisWorkbook module.
The code is based on you creating a temporary worksheet called PartRecord to store the form’s data.
HTH :cheers:
-
Bonriki
AskWoody Lounger
-
-
RetiredGeek
AskWoody_MVPJune 14, 2016 at 7:20 pm #1567552Phil,
Could you post your update file? :cheers:
-
Bonriki
AskWoody Lounger
-
-
Andrew Lockton
AskWoody_MVPJune 15, 2016 at 1:59 am #1567594You need to refer to the worksheet in the same way it was done earlier in the same macro
ActiveWorkbook.Worksheets(“Monthly Report”)And I’m not sure why you want to .Select the sheet. I would expect that .Activate might be more useful.
But why do you need a temp sheet to hold this info? Why can the data not go onto the “Monthly Report” until a certain point in time. Surely it doesn’t become ‘final’ until the person submits the sheet. I would be putting the info straight onto the report and not be bothered with a temp sheet to hold the same information until it needs to be transferred across.
-
Bonriki
AskWoody LoungerJune 15, 2016 at 5:18 pm #1567641But why do you need a temp sheet to hold this info? Why can the data not go onto the “Monthly Report” until a certain point in time. Surely it doesn’t become ‘final’ until the person submits the sheet. I would be putting the info straight onto the report and not be bothered with a temp sheet to hold the same information until it needs to be transferred across.
Andrew
Not sure I understand. My users wish to enter data, save it and then come back to it later by opening the workbook again. I didn’t believe rerunning the userform retained the previously entered data, which is what my users wish to do, edit the data .
-
-
Maudibe
AskWoody_MVPJune 15, 2016 at 8:20 pm #1567653Bonriki,
In a recent project for another member, there was a form where data was entered and stored to a hidden sheet. A save button sent the forms data to the sheet to be stored. When the form was activated, the data was pulled back from the sheet to have all fields populated on the form when it reopened. This method work for reopening the form in the same excel session or opening the project at a later date
Save Button: Stores data on hidden sheet
Code:Private Sub CommandButton2_Click() [COLOR=”#008000″]’————————————- ‘SAVE AND WRITE TO HIDDEN SHHET[/COLOR] With Worksheets(“Hidden”) For I = 1 To 10 .Cells(I, 1) = Me.Controls(“ComboBox” & I).Value ‘WRITE TO HIDDEN SHEET Next I End With End Sub
Open Userform: Retrieves data from hidden sheet
Code:Private Sub UserForm_Activate() [COLOR=”#008000″]’————————————- ‘WHEN FORM OPENS: LOAD VALUES FROM HIDDEN SHEET[/COLOR] For I = 1 To 10 With Me.Controls(“ComboBox” & I) .Value = Worksheets(“Hidden”).Cells(I, 1) End With Next I End Sub
Here is the link for the thread:
http://windowssecrets.com/forums/showthread//174654-Trying-to-calculate-income-spread-across-months?p=1056834&viewfull=1#post1056834I like to keep the naming convention of the form objects as (ex. ComboBox4) so I can loop through them.
HTH,
Maud -
Bonriki
AskWoody Lounger
-
-
Andrew Lockton
AskWoody_MVPJune 15, 2016 at 10:00 pm #1567678The userform doesn’t retain the data but it can load it from the same sheet that is populated by the userform anytime.
See the attached version of your workbook. You have lookup lists already setup on a sheet and it seemed pointless to recreate those lists in vba – so I changed that too.
44763-Finance-Commercial-Sales-Monthly-ReportYour file naming pattern seems flawed. Saving to C:UsersUsername won’t work unless they ONLY choose themselves from the list and this matches their userid on that machine. Better to not even bother asking the user for the name and use the username property or the environment variable to arrive at the user’s name and/or documents folder location.
-
Bonriki
AskWoody LoungerJune 15, 2016 at 11:17 pm #1567686Thanks Andrew
The workbook doesn’t seem to want to behave. When I double click to open the file opens with Protected view warning with “Enable Editing” highlighted then when clicked it gives VBA error 91
44764-error91
and then when I click “Debug” I get the following
44765-91DebugHowever, if I open the file from Excel it all works fine as expected. The preference is for the users to have the file on their desktop, double click to open and fill in the data.
Reviewing the code, other the initialise sub, I cannot see what you have changed plus the email function doesn’t work
-
-
Andrew Lockton
AskWoody_MVPJune 16, 2016 at 2:25 am #1567690Phil
It works on my machine by double clicking to open so the issue might be local to your machine. Perhaps you have multiple versions of this running.
Interestingly, it appears creating a new workbook triggers the Auto_Open macro so it appears that Excel behaves differently to Word and you probably don’t need the Auto_New macro at all.
I didn’t change anything about the email macro but perhaps that issue is caused because the form was closed in the last line of the Save macro. Try removing that to keep the form open while the email macro runs
-
Maudibe
AskWoody_MVPJune 16, 2016 at 4:12 pm #1567795Bonriki,
Yes, you are right. As written, the code will work only for combo boxes. The method of writing data from an objects to cells then cells to objects can be easily modified. The point I am trying to demonstrate is the simplicity, consistency, and integrity of saving settings to a sheet then back to a form.
If you have multiple types of objects, the code can be modified to something like:
Code:Private Sub CommandButton2_Click() [COLOR=”#008000″]’————————————- ‘SAVE AND WRITE TO HIDDEN SHEET[/COLOR] With Worksheets(“Hidden”) For I = 1 To 5 [COLOR=”#008000″]’5 COMBOBOX CONTROLS[/COLOR] .Cells(I, 1) = Me.Controls(“ComboBox” & I).Value ‘WRITE TO HIDDEN SHEET Next I For I = 1 To 6 [COLOR=”#008000″]’6 TEXTBOX CONTROLS[/COLOR] .Cells(I+5, 1) = Me.Controls(“TextBox” & I).Value ‘WRITE TO HIDDEN SHEET Next I For I = 1 To 3 [COLOR=”#008000″]’3 CHECKBOX CONTROLS[/COLOR] .Cells(I+11, 1) = Me.Controls(“CheckBox” & I).Value ‘WRITE TO HIDDEN SHEET Next I End With End Sub
This is provided you use a naming convention that you can loop through objects then vice versa.
HTH,
Maud -
Andrew Lockton
AskWoody_MVPJune 16, 2016 at 7:27 pm #1567816Phil
Maud’s code is actually independent of the ‘type’ for each control. It just so happens to coincide with default names given to controls added to a userform. You have already renamed all your text and comboboxes so it is not going to give you a useful result. However, it is illustrating a good principle of trying to reduce the amount of coding required to handle updates to your form.
A more robust way would be to loop through every control on the userform and find attribute(s) that indicate the control should be worked on. For instance, if you used the Tag property of each field to store the cell address the field corresponds with then you don’t have to explicitly handle that repetitively in handcrafted vba.
Code:Dim aCtl As Control For Each aCtl In Me.Controls Select Case TypeName(aCtl) Case "ComboBox", "TextBox" ActiveWorkbook.Sheets("Monthly Report").Range(aCtl.Tag) = aCtl.Value End Select Next aCtl
This method allows you to add/delete/change the userform quickly without actually needing to make vba changes at all (let alone in multiple places). See attached file for this methodology applied to your file 44772-Finance-Commercial-Sales-Monthly-Report2
-
Bonriki
AskWoody Lounger
-
-
RetiredGeek
AskWoody_MVPJune 16, 2016 at 7:50 pm #1567821Andrew,
Very Cool!
44299-Joe-Cool -
Bonriki
AskWoody Lounger -
Maudibe
AskWoody_MVP -
Maudibe
AskWoody_MVPJune 17, 2016 at 6:06 pm #1567905Just messing around with this further but using the ControlTipText property instead.
Code:With TextBox1 Range(.ControlTipText) = TextBox1.value End With
It gives the added benefit of displaying where the value will be stored when hovering over the textbox. Real handy in the development stage of testing.
Hover over the control
44782-bonriki -
Bonriki
AskWoody Lounger -
Andrew Lockton
AskWoody_MVPJune 22, 2016 at 3:45 am #1568308Phil
IMHO, your userform is an answer in search of a problem. The actual worksheet your form reads/writes to should be where the users put all their data. You can reformat it a bit to make is sexier but it is always going to be FAR simpler to just let them edit it directly. The userform adds a level of complexity without any real payoff in terms of useability.
If you need to do a 3 column dataset where the users can edit all three fields with multiple records, this is very simple to do directly on a worksheet. It is much more complex in a userform and most people would actually use a second userform just to add/edit a multiple column list field. Do you really need that level of complexity?
-
-
Maudibe
AskWoody_MVPJune 22, 2016 at 7:06 pm #1568381While Andrew has a point with simplicity, forms as well as sheets themselves are as complex as you make them. In their defense, opening a form moves the user’s attention away from the clutter of sheet data and emphasizes the field(s) where the input is required. They add additional real estate on demand than takes it out of site when not needed. Forms are everywhere. They offer structure, design, creativity, and interest and are used extensively on all types of applications and websites.
They may be a bit more challenging in design mode but there are big payoffs at run time from the users point of view. After all, that’s why designers program applications. IMHO, forms offer one of the biggest bangs for the buck in programming.
Maud
Viewing 16 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Giving UniGetUi a test run.
by
RetiredGeek
29 seconds ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
7 hours, 37 minutes ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
5 hours, 36 minutes ago -
Auto Time Zone Adjustment
by
wadeer
12 hours, 6 minutes ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
9 hours, 46 minutes ago -
Manage your browsing experience with Edge
by
Mary Branscombe
3 hours, 34 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
1 hour, 18 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
5 hours, 35 minutes ago -
Apps included with macOS
by
Will Fastie
5 hours, 13 minutes ago -
Xfinity home internet
by
MrJimPhelps
5 hours, 8 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
5 hours, 6 minutes ago -
Debian 12.11 released
by
Alex5723
1 day, 9 hours ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
1 day, 12 hours ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
16 hours, 22 minutes ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
8 hours, 47 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
2 days, 5 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
1 day, 20 hours ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
2 days, 8 hours ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
2 days ago -
Some advice for managing my wireless internet gateway
by
LHiggins
1 day, 8 hours ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
10 hours, 18 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
2 days, 18 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
6 hours, 7 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
2 days, 4 hours ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
3 days, 7 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
1 day, 15 hours ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
1 day, 4 hours ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
3 days, 10 hours ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
3 days, 10 hours ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
1 hour, 5 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.