msg / input box

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
675
Office Version
  1. 365
Platform
  1. Windows
good afternoon,

After several failures I still have an issue and hope some kind member can help?

i would like to generate a message upon opening the applicable file that would ask the user if they want to input data into another worksheet (within same file) & choose Y or N if yes , a input box would appear . The date would be in D2 , worksheet ref.
Many thanks in advance

KR
Trevor 3007
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
To have the macro to be launched when you open the workbook, go in VBA, 2x click "this workbook" in the left column below the sheets names and paste

Code:
Private Sub Workbook_Open()
If MsgBox("Input Data ?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Dim myValue As Variant
myValue = InputBox("Enter Date")
Do While myValue = "" Or Not IsDate(myValue)
        MsgBox ("You did not enter a date in the correct format!"), vbCritical, Error
        myValue = InputBox("Please Enter the Report Date with format dd/mm/yyyy", "Enter Date")
    Loop
Sheets("ref.").Range("D2").Value = myValue
End Sub

You can test the macro by clicking the play button in the bar or close and open the workbook. Always a good idea to save a copy before trying.
 
Last edited:
Upvote 0
To have the macro to be launched when you open the workbook, go in VBA, 2x click "this workbook" in the left column below the sheets names and paste

Code:
Private Sub Workbook_Open()
If MsgBox("Input Data ?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Dim myValue As Variant
myValue = InputBox("Enter Date")
Do While myValue = "" Or Not IsDate(myValue)
        MsgBox ("You did not enter a date in the correct format!"), vbCritical, Error
        myValue = InputBox("Please Enter the Report Date with format dd/mm/yyyy", "Enter Date")
    Loop
Sheets("ref.").Range("D2").Value = myValue
End Sub

You can test the macro by clicking the play button in the bar or close and open the workbook. Always a good idea to save a copy before trying.





Hi,

thank you for your reply,

Sorry I think I have mislead you?I need the user to input text NOT a date. sorry for the confusion, also the could you format the text to Proper case too?

Many thanks :}
 
Upvote 0
hi,

sorry my bad... cell ref should be D1 :/

hope you can sort?
 
Upvote 0
hi,

sorry my bad... cell ref should be D1 :/

hope you can sort?

Simply change the last line (before "End sub") to
Code:
[COLOR=#333333][FONT=monospace][I]Sheets("ref.").Range("D1").Value = myValue[/I][/FONT][/COLOR]
 
Last edited:
Upvote 0
Hi,

thank you for your reply,

Sorry I think I have mislead you?I need the user to input text NOT a date. sorry for the confusion, also the could you format the text to Proper case too?

Many thanks :}

Code:
Private Sub Workbook_Open()
If MsgBox("[COLOR=#ff8c00]Input Data ?[/COLOR]", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Dim myValue As Variant
myValue = InputBox("[COLOR=#ff8c00]Enter text[/COLOR]")
Sheets("ref.").Range("D1").Value = Application.WorksheetFunction.Proper(myValue)
End Sub
 
Last edited:
Upvote 0
Code:
Private Sub Workbook_Open()
If MsgBox("[COLOR=#ff8c00]Input Data ?[/COLOR]", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Dim myValue As Variant
myValue = InputBox("[COLOR=#ff8c00]Enter text[/COLOR]")
Sheets("ref.").Range("D1").Value = Application.WorksheetFunction.Proper(myValue)
End Sub

Good morning Kamolga,

sorry for not getting back to you ASAP & thank you for your your help.

Your code works great , but I must have had a bit of a DER day yesterday as I also forgot to include in my request that the applicable worksheet , the work tab would change to the same name as in D1...



Could you be a kind chap and sort? This would be the last request BTW

Many thanks in advance
Trevor3007
 
Upvote 0
When you click sheet1(ref.) in VBA, you should have the properties below where you can change the name (the first one). If not, click the icon in the bar with a finger pointing a white rectangle.
Now change sheet1 (can be sheet2, 3 or whatever number) into Ref and then click this workbook and paste

Code:
[I][LEFT][COLOR=#333333][FONT=monospace]Private Sub Workbook_Open()
If MsgBox("[/FONT][/COLOR][COLOR=#ff8c00][COLOR=#ff8c00][FONT=monospace]Input Data ?[/FONT][/COLOR][/COLOR][COLOR=#333333][FONT=monospace]", vbYesNo + vbQuestion) = vbNo Then Exit Sub
[/FONT][/COLOR][/LEFT]
[/I][LEFT][I][COLOR=#333333][FONT=monospace]Dim myValue As Variant
myValue = InputBox("[/FONT][/COLOR][COLOR=#ff8c00][COLOR=#ff8c00][FONT=monospace]Enter text[/FONT][/COLOR][/COLOR][/I][COLOR=#333333][FONT=monospace][I]")
[/I][/FONT][/COLOR]
[COLOR=#333333][FONT=monospace][I]Ref.Range("D1").Value = Application.WorksheetFunction.Proper(myValue)
Ref.name=[/I][COLOR=#333333][FONT=monospace][I]Application.WorksheetFunction.Proper(myValue)[/I][/FONT][/COLOR][I]
End Sub
[/I][/FONT][/COLOR][/LEFT]

Note that there are restriction in amount and special characters (I don't know exactly which). So you might get an error (Ref.name=
Application.WorksheetFunction.Proper(myValue) highlighted in yellow) if the inputbox is empty or does not meet sheet name requirement

Amso n
ote that changing the name in properties and use them in your code is a very good habbit in VBA, so that if someone changes the name of a sheet, your codes still works perfectly.
<strike></strike>
 
Last edited:
Upvote 0
When you click sheet1(ref.) in VBA, you should have the properties below where you can change the name (the first one). If not, click the icon in the bar with a finger pointing a white rectangle.
Now change sheet1 (can be sheet2, 3 or whatever number) into Ref and then click this workbook and paste

Code:
[I][LEFT][COLOR=#333333][FONT=monospace]Private Sub Workbook_Open()
If MsgBox("[/FONT][/COLOR][COLOR=#ff8c00][COLOR=#ff8c00][FONT=monospace]Input Data ?[/FONT][/COLOR][/COLOR][COLOR=#333333][FONT=monospace]", vbYesNo + vbQuestion) = vbNo Then Exit Sub
[/FONT][/COLOR][/LEFT]
[/I][LEFT][I][COLOR=#333333][FONT=monospace]Dim myValue As Variant
myValue = InputBox("[/FONT][/COLOR][COLOR=#ff8c00][COLOR=#ff8c00][FONT=monospace]Enter text[/FONT][/COLOR][/COLOR][/I][COLOR=#333333][FONT=monospace][I]")
[/I][/FONT][/COLOR]
[COLOR=#333333][FONT=monospace][I]Ref.Range("D1").Value = Application.WorksheetFunction.Proper(myValue)
Ref.name=[/I][COLOR=#333333][FONT=monospace][I]Application.WorksheetFunction.Proper(myValue)[/I][/FONT][/COLOR][I]
End Sub
[/I][/FONT][/COLOR][/LEFT]

Note that there are restriction in amount and special characters (I don't know exactly which). So you might get an error (Ref.name=
Application.WorksheetFunction.Proper(myValue) highlighted in yellow) if the inputbox is empty or does not meet sheet name requirement

Amso n
ote that changing the name in properties and use them in your code is a very good habbit in VBA, so that if someone changes the name of a sheet, your codes still works perfectly.
<strike></strike>



hi

so very grateful of you help. I pasted the code into 'this workbook' but it does not change the applicable tab name? it the 2nd sheet BTW :}

KR
Trevor 3007
 
Upvote 0
Hi,

this is the code use on another workbook:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

''''''''''''''''''''''''''''''''''''''''''''


'Forces text to Proper case for the range d1


''''''''''''''''''''''''''''''''''''''''''''


If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub






    On Error Resume Next


    If Not Intersect(Target, Range("d1")) Is Nothing Then


        Application.EnableEvents = False


        Target = StrConv(Target, vbProperCase)


        Application.EnableEvents = True


    End If


    On Error GoTo 0




   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(False, False) = "D1" Then
      ActiveSheet.Name = Target.Value & "-data"
   End If






End Sub


its fine for that workbook, but I need the combo (msg/input box) as in your code.

Are you able to sort?

so sorry for any incon...hope your BH weekend is going OK?

KR
Trevor3007
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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