Input box

     

    >
  • Inputbox enables the user to enter the data in Dialogue box
  •  

  • Data which is entered by user stored in a string, and used later
  •  

     

  • Input Box always returns STRING value
  •  

  • Prompt: Text on INPUT Box
  •  

  • Title: Title of Input Box, It is optional
  •  

  • Default: Default value of Input Box(optional)
  •  

     

  • XPos,YPos:Indicates about position of Input Box., If we are not mentioned any thing input box displays on center of worksheet
  •  

     

    How input box works?

     

     

  • Value entered in INPUTBOX stored in variable
  • We can use than variable based on requirement
  •  

     

    State about TYPE in Input box:

     

  • If TYPE is 0(zero) = Inputbox returns TEXT
  • If TYPE is 8(zero) = Inputbox returns RANGE Object
  •  

     

    application.Inputbox("prompt")

     

    To return range: Assing type as 8 in input box

    use SET key word(use SET key word to assign value to Objects)

     

    Dim j As Range
    Set j = Application.InputBox("Select the range", Type:=8)

     

     

    Example #1:

     

     

     

    Example #2:

     

     

    Code to Write:

     

    Private Sub CommandButton1_Click()
    '1)Define a variable to store data which is mentioned in INPUTBOX
    Dim i As String
    i = Application.InputBox("Sriguranjani", "Welcome")
    '2)Define a range where we require to paste the data which is stored in variable
    Range("A1:A11").Value = "hello " & i & " Good Morning"
    '3)Store the data from First data cell to last data cell in a variable
    Dim s As Integer
    s = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    Range(Cells(1, 1), Cells(s, 1)).Select
    With Selection
    '4)Specify the font size
    .Font.Size = 15
    '5)Specify the Horizontal alignment
    .HorizontalAlignment = xlCenterAcrossSelection
    auto adjust the cell width based on text available., all the data need to fit in a cell only
    .Cells.EntireColumn.AutoFit
    '6)Assign a font family
    .Font.Name = "High Tower Text"
    '7)Assign a font Color
    .Font.ColorIndex = 3
    End With
    End Sub

     

    Code to Erase:

     

    Private Sub CommandButton2_Click()
    Dim s As Integer
    1)Select all the data using end xl down method
    Q = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    Range(Cells(1, 1), Cells(Q, 1)).Select
    2)To clear\erase all the text available in excel sheet which is mentioned in range
    Selection.Clear
    3)resize the column width
    Columns("A").ColumnWidth = StandardWidth
    End Sub