I've been having the same problems. I tried all of the codes below. The first time, the returned range from the inputbox is "Nothing", whether I do select or do not select a range, and whether I press OK or cancel afterwards.
The weird thing is, The subs and functions do work the second time I run them. Please provide more insight into the problem (Use Excel 2002 SP3).
Regards,
Davey Wijngaards
Subs and Functions Used:
'
VB:
Sub InputboxDemo()
Dim myRange As Range
On Error Resume Next
Set myRange = Application.InputBox(Prompt:="Please select range", _
Title:="Mahipalreddy.com-VBAhelp", Type:=8)
If (myRange Is Nothing) = False Then
For Each rngCell In myRange.Cells
If IsEmpty(rngCell.Value) = False Then
MsgBox rngCell.Value
End If
Next rngCell
End If
End Sub
Sub foo()
Dim Rng As Range
Set Rng = InputRange(Prompt:="Select a range", Title:="foo", Force:=True)
If Not Rng Is Nothing Then Rng.EntireRow.Select
End Sub
Function InputRange(Optional Prompt As String = "", Optional Title As String = "", _
Optional Force As Boolean = False) As Range
Dim retry As Boolean
On Error Resume Next
Do
Set InputRange = Application.InputBox(Prompt:=Prompt, Title:=Title, Type:=8)
If InputRange Is Nothing And Force And Not retry Then
retry = True
Prompt = "YOU MUST SELECT A RANGE!" & Chr(13) & Prompt
End If
Loop While InputRange Is Nothing And Force
On Error Goto 0
End Function
Sub GetRange()
Dim Rng As Range
On Error Resume Next
Set Rng = Range("A1")
Set Rng = Application.InputBox(Prompt:="Enter range", Type:=8)
If Rng Is Nothing Then
MsgBox "Operation Cancelled"
Else
Rng.Select
End If
End Sub
Sub GetUserRange()
Dim UserRange As Range
Output = 565
Prompt = "Select a cell for the output."
Title = "Select a cell"
On Error Resume Next
Set UserRange = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8)
If UserRange Is Nothing Then
MsgBox "Canceled."
Else
UserRange.Range("A1") = Output
End If
End Sub
Sub GetAdres()
Dim Last As Range, mes As String
mes = "Select any cell in one of the first 10 rows"
On Error Resume Next
Set Last = Application.InputBox(Prompt:=mes, Type:=8)
If Last Is Nothing Then Exit Sub
MsgBox Last.Address
End Sub
Bookmarks