View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Ranges & Inputboxes?

Dim FIRST, SECOND, THIRD As Range

The above statement is not doing what you think it is doing... only THIRD is
declared as a Range, FIRST and SECOND are declared as Variant. In VB, you
must declare each variable's Type individually. If you wanted to do it all
on one line, you would have to do it like this...

Dim FIRST As Range, SECOND As Range, THIRD As Range

If FIRST.Address = "" Then
Exit Sub
MsgBox "--:" & FIRST.Address & ":--"
End If


Now, as for the above lines of code, the MsgBox statement will never be
executed because you exited the Sub in the previous line. Reverse those two
lines and the MsgBox will appear and then, when it is dismissed, the Sub
will be exited.

--
Rick (MVP - Excel)


"Faraz A. Qureshi" wrote in
message ...
I always get into a trouble when referring to a range via an inputbox and a
Cancel button is clicked or it is left Blank. Any suggestions?

Furthermore, what might be wrong with the following code?

Sub CHECK()

Dim FIRST, SECOND, THIRD As Range

Set FIRST = Application.InputBox("FIRST!", , , , , , , 8)
If FIRST.Address = "" Then
Exit Sub
MsgBox "--:" & FIRST.Address & ":--"
End If

Set SECOND = Application.InputBox("SECOND!", , , , , , , 8)
If SECOND.Address = "" Then
Exit Sub
MsgBox "--:" & SECOND.Address & ":--"
End If

Set THIRD = Application.InputBox("THIRD", , , , , , , 8)
If THIRD.Address = "" Then
Exit Sub
MsgBox "--:" & THIRD.Address & ":--"
End If

End Sub

--
Best Regards,

Faraz