'Application.InputBox Method
'Displays a dialog box for user input. Returns the information entered in the dialog box.
'Syntax
'expression.InputBox(Prompt, Title, Default, Left, Top, HelpFile, HelpContextID, Type)
'expression A variable that represents an Application object.
'The following table lists the values that can be passed in the Type argument. Can be one or _
a sum of the values. For example, for an input box that can accept both text and numbers, set Type to 1 + 2.
'Value Meaning
'0 A Formula
'1 A Number
'2 Text (a string)
'4 A logical value (True or False)
'8 A cell reference, as a Range object
'16 An error value, such as #N/A
' 64 An array of values
'Toggle between gridlines
Sub ToggleGridlines()
ActiveWindow.DisplayGridlines = Not ActiveWindow.DisplayGridlines
End Sub
Sub TestAppInputBox()
Dim mnt As String
Dim id As Long
Dim myformula As String
Dim formulacell As Range
Dim copyrange As Range
Dim destinationrange As Range
mnt = Application.InputBox("Enter the month") 'use of application inputbox
Range("a1").End(xlDown).Offset(1, 0).value = mnt
id = Application.InputBox("Enter the Id no", , , , , , , 1) 'putting validation in application inputbox
Range("d1").End(xlDown).Offset(1, 0).value = id
myformula = Application.InputBox("Enter the Formula:", Type:=0, _
Default:="=Sum(") 'putting formula by user for calculation _
also use of default type
Range("k2").FormulaLocal = myformula
Set formulacell = Application.InputBox("Enter the formulacell", Type:=8) 'entering the formula cell
formulacell.FormulaLocal = myformula
Set copyrange = Application.InputBox("Choose range to copy", Type:=8) 'Using inputbox to copy and paste
Set destinationrange = Application.InputBox("Choose destination cell", Type:=8)
copyrange.Copy destinationrange
End Sub
Sub ReturnArray() 'User input in array and performing calculation based on array
Dim testarray() As Variant
Dim counter As Long
Dim destinationrange As Range
testarray() = Application.InputBox("Choose the range of cells", Type:=64)
For counter = LBound(testarray, 1) To UBound(testarray, 1)
testarray(counter, 1) = Int(testarray(counter, 1) / 60) & _
" Hours & " & (testarray(counter, 1) Mod 60) & " Minutes"
Next counter
Set destinationrange = Application.InputBox("Choose the destination", Type:=8)
Set destinationrange = Range(destinationrange, destinationrange.Offset(UBound(testarray, 1) - 1, 0))
destinationrange = testarray
End Sub
No comments:
Post a Comment