Macro with input box.

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
I need a macro please that when I select a cell or range of cells and run the code an input box pops up and does the following.

If I enter a number and press enter it places a word or sentence into the cell(s).

1. Test
2. No data available
3. Test 3

And so on up to about 10. I can change in the code the words or sentences to suit.

Thanks.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi,
To use an Input Box in your macro :
 
Upvote 0
Hi,
To use an Input Box in your macro :
Thanks but that doesn't really mean anything to me!
 
Upvote 0
Hopefully, you do no expect to be spoon-fed ...

Do you already have the initial premises of your future macro ?
 
Upvote 0
Is this what you're looking for?
VBA Code:
Option Base 1
Sub Dazz()
Dim rng As Range, cell As Range
Dim mySelectionNum As Integer, mySelectionText As String, myList()
myList = Array("No Data Available", "Test1", "Test2", "Test3", "Test4", "Test5", "Test6" _
    , "Test7", "Test8", "Test9", "Test10")
mySelectionNum = Application.InputBox("Please enter number.", "Selection Number", Type:=1)
mySelectionText = myList(mySelectionNum)
Set cell = Application.InputBox("Select a cell(s) for placement", "Cell Selection", _
    Type:=8)
cell.Value = mySelectionText
End Sub
 
Upvote 0
VBA Code:
Sub Macro_With_Inputbox()
    Dim R As Range, rng As Range
    Dim I As Long
    Dim Msg As String
    Dim Ans As Variant

    Msg = "1. Test" & vbCr
    Msg = Msg & "2. No data available" & vbCr
    Msg = Msg & "3. Test 3"

    Ans = InputBox(Msg, "Make Selection")
    If Ans = "" Then Exit Sub                         'cancel

    If IsNumeric(Ans) Then
        I = Val(Ans)
        Select Case I
        Case 1
            Msg = "Test"
        Case 2
            Msg = "No data available"
        Case 3
            Msg = "Test 3"
'        Case 4
'            Msg = "Test 4"
'        Case 5
'            Msg = "Test 5"
'        Case 6
'            Msg = "Test 6"
'        Case 7
'            Msg = "Test 7"
'        Case 8
'            Msg = "Test 8"
'        Case 9
'            Msg = "Test 9"
'        Case 10
'            Msg = "Test 10"
        Case Else
            MsgBox "Invalid selection"
            Exit Sub
        End Select

        Set rng = Selection
        For Each R In rng
            R.Value = Msg
        Next R
    Else
        MsgBox "Invalid selection"
    End If
End Sub
 
Upvote 0
Both work great, much obliged squires.
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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