Data Input on Workbook Open

default_name

Board Regular
Joined
May 16, 2018
Messages
170
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Hey guys,

I am trying to implement an input box that appears when the user first opens the workbook.
Here is how I would like it to function:
  1. User opens the workbook
  2. A prompt appears, which asks the user to enter a balance (which is stored as a variable called 'balance')
    • If the user just hits enter or Cancel (without inputting a new balance), then the box disappears, and the value in cell B1 remains unchanged (it remains at whatever value it was already set to prior to opening the workbook)
    • If the user enters a value and hits OK or enter, the input box disappears, and the value of cell B1 is updated to reflect the new 'balance'
I tried to get it started using some input box code I found online, but I am having issues with even the initial setup (not to mention the Cancel/no data inputted function).
Here is what I currently have started.

VBA Code:
Private Sub Workbook_Open()
Dim balance As Variant
Do
    balance = InputBox("What is your current balance?")
    If IsNumeric(balance) Then Exit Do
    Range("B1").Value = account
Loop
End Sub

Thanks in advance
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
What is the name of the sheet that holds the balance?
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Workbook_Open()
   Dim balance As Variant
   balance = InputBox("What is your current balance?")
   If balance = "" Then Exit Sub
   Sheets("2020").Range("B1").Value = balance
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Private Sub Workbook_Open()
   Dim balance As Variant
   balance = InputBox("What is your current balance?")
   If balance = "" Then Exit Sub
   Sheets("2020").Range("B1").Value = balance
End Sub
Works perfectly! Thanks for all your help Fluff!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Real quick follow-up question to the provided solution.
Hopefully this is ok to ask...if not I can just make a brand new thread.

I am trying to incorporate a Protect Sheet function with the provided code, in the event that "" (no new data) is inputted.
I incorporated a Protect Sheet function, that seems to work just fine, in the event that any new data is inputted, but adding the same Protections (even in the event of a "") seems to be a challenge.

VBA Code:
Private Sub Workbook_Open()
Dim balance As Variant
balance = InputBox("What is your current balance?")
If balance = "" Then
                Sheets("2020").Select
                ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _False
           Exit Sub
Sheets("2020").Range("B1").Value = balance
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _False
Sheets("2020").Select
End Sub
 
Upvote 0
Hello Default Name,
you got some syntax error. Try with some changes:
VBA Code:
Private Sub Workbook_Open()
Dim balance As Variant
balance = InputBox("What is your current balance?")
If balance = "" Then
                Sheets("2020").Select
                ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
                
Exit Sub
End If
Sheets("2020").Range("B1").Value = balance
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
Sheets("2020").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,993
Latest member
Seri

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