Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Object variable problem

I am trying to set an object variable. I get an error message when I
try to do the following:

Dim NumberofColumns As Variant
Dim BMax As Integer

Set NumberofColumns = Application.InputBox(prompt:="Enter Number of 2D
Elements", Type:=1)

If NumberofColumns Is Nothing Then
MsgBox ("Operation Canceled")
Exit Sub
Else
BMax = NumberofColumns
End If

When I enter data or click on CANCEL the error says Type Mismatch. Is
this because Variant and Type:= 1 are not compatible?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Object variable problem

Get rid of the 'Set' keyword in the line of code. InputBox
returns an object type variable only when Type is set to 8.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"ExcelMonkey " wrote
in message ...
I am trying to set an object variable. I get an error message

when I
try to do the following:

Dim NumberofColumns As Variant
Dim BMax As Integer

Set NumberofColumns = Application.InputBox(prompt:="Enter

Number of 2D
Elements", Type:=1)

If NumberofColumns Is Nothing Then
MsgBox ("Operation Canceled")
Exit Sub
Else
BMax = NumberofColumns
End If

When I enter data or click on CANCEL the error says Type

Mismatch. Is
this because Variant and Type:= 1 are not compatible?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Object variable problem

ExcelMonkey,

Try something like:

Sub test()
Dim NumberofColumns As Variant
Dim BMax As Integer

NumberofColumns = Application.InputBox(prompt:="Enter Number of 2D
Elements", Type:=1)

If TypeName(NumberofColumns) = "Boolean" Then
If NumberofColumns = False Then
MsgBox ("Operation Canceled")
Exit Sub
End If
End If
BMax = NumberofColumns
End Sub


I use TypeName statement so that you can use 0 as a number. False = 0

Rob


"ExcelMonkey " wrote in message
...
I am trying to set an object variable. I get an error message when I
try to do the following:

Dim NumberofColumns As Variant
Dim BMax As Integer

Set NumberofColumns = Application.InputBox(prompt:="Enter Number of 2D
Elements", Type:=1)

If NumberofColumns Is Nothing Then
MsgBox ("Operation Canceled")
Exit Sub
Else
BMax = NumberofColumns
End If

When I enter data or click on CANCEL the error says Type Mismatch. Is
this because Variant and Type:= 1 are not compatible?


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Object variable problem

You guys rock!

Thank

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Object variable problem

A number is not an object. So remove the "set". Then check for
"numberOfColumns = false not nothing

"ExcelMonkey " wrote in message
...
I am trying to set an object variable. I get an error message when I
try to do the following:

Dim NumberofColumns As Variant
Dim BMax As Integer

Set NumberofColumns = Application.InputBox(prompt:="Enter Number of 2D
Elements", Type:=1)

If NumberofColumns Is Nothing Then
MsgBox ("Operation Canceled")
Exit Sub
Else
BMax = NumberofColumns
End If

When I enter data or click on CANCEL the error says Type Mismatch. Is
this because Variant and Type:= 1 are not compatible?


---
Message posted from http://www.ExcelForum.com/



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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM
Problem Using an Object Variable in a Class Definition Boxman Excel Programming 2 August 28th 03 03:05 AM
Object Variable or With Block variable not set? Chris M.[_3_] Excel Programming 3 August 26th 03 04:30 PM


All times are GMT +1. The time now is 04:53 PM.

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

About Us

"It's about Microsoft Excel"