Pages

Saturday, March 24, 2012

InputBox

Sub input_box()

    thename = InputBox("what is your Name", "Greeting", Application.UserName)

    MsgBox "Hi " & thename

End Sub

Sub addsheets()

    Dim prompt As String

    Dim caption As String

    Dim defvalue As Integer

    Dim numsheets As String

    prompt = "how many sheets do you want to add?"

    caption = "Tell me my lord......."

    defvalue = 1

    numsheets = InputBox(prompt, caption, defvalue)

    If numsheets = "" Then Exit Sub

    If IsNumeric(numsheets) Then

        If numsheets > 0 Then Sheets.Add Count:=numsheets

    Else

        MsgBox "Invalid number"

    End If

End Sub

Sub selectRange()

    Dim Rng As Range

    On Error Resume Next

    Set Rng = Application.InputBox(prompt:="specify a range:", Type:=8)

    If Rng Is Nothing Then Exit Sub

    MsgBox "you have selected a range" & Rng.Address

End Sub

 

No comments:

Post a Comment