Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Ranges & Inputboxes?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Ranges & Inputboxes?

Thanx 4 the first line Rick!

But the object of msgbox is to appear only and only if any range is
selected, otherwise as stated b4 the code should terminate if inputbox is
cancelled or left blank.

--
Best Regards,

Faraz


"Rick Rothstein" wrote:

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Ranges & Inputboxes?

In that case, it looks like you left out the Else statement. Try this (and
modify the other parts of your code accordingly)...

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

--
Rick (MVP - Excel)


"Faraz A. Qureshi" wrote in
message ...
Thanx 4 the first line Rick!

But the object of msgbox is to appear only and only if any range is
selected, otherwise as stated b4 the code should terminate if inputbox is
cancelled or left blank.

--
Best Regards,

Faraz


"Rick Rothstein" wrote:

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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Ranges & Inputboxes?

Thanx again Rick but:

1. If the inputbox is left BLANK or CANCELLED I want the code to END! &

2. Why would an else statement be required? if the condition is not met the
CODE should progress onwards. Seems like I am wrong at something at:

FIRST.Address = ""

It should be something else instead of "".

--
Best Regards,

Faraz


"Rick Rothstein" wrote:

In that case, it looks like you left out the Else statement. Try this (and
modify the other parts of your code accordingly)...

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

--
Rick (MVP - Excel)


"Faraz A. Qureshi" wrote in
message ...
Thanx 4 the first line Rick!

But the object of msgbox is to appear only and only if any range is
selected, otherwise as stated b4 the code should terminate if inputbox is
cancelled or left blank.

--
Best Regards,

Faraz


"Rick Rothstein" wrote:

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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
userform and inputboxes pswanie Excel Programming 1 January 3rd 08 04:09 PM
Positioning Userforms, InputBoxes Pflugs Excel Discussion (Misc queries) 1 July 10th 07 06:12 PM
connecting 2 inputboxes and using the autofill Mike Excel Programming 4 September 29th 06 12:37 PM
InputBoxes Sean Excel Programming 2 July 19th 06 06:09 PM
InputBoxes Exceptions ianripping[_42_] Excel Programming 3 April 8th 04 09:34 PM


All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"