Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Is SET Statement only for Range?

Upon running the following code I get a message "Compile Error: Object
Required"

Sub FQCHECK()
Dim FQTEXT As String
Set FQTEXT = Application.InputBox(PROMPT:="Insert Keyword", Type:=2)
MsgBox ("YOU TYPED " & FQTEXT)
End Sub

While the following code executes perfectly:

Sub FQCHECK()
Dim FQRANGE As Range
Set FQRANGE = Application.InputBox(PROMPT:="SELECT CELL", Type:=8)
MsgBox ("YOU SELECTED " & FQRANGE.Address)
End Sub

What might be the cause? Is the Set statement only suitable for selection
range? Because the first piece of code works fine if entered as:
Sub FQCHECK()
Dim FQTEXT As String
FQTEXT = Application.InputBox(PROMPT:="Insert Keyword", Type:=2)
MsgBox ("YOU TYPED " & FQTEXT)
End Sub
--
Best Regards,
FARAZ A. QURESHI
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Is SET Statement only for Range?

Set is for Objects:

1. ranges
2. worksheets
3. workbooks
4. graphics

Don't use it for most variables
--
Gary''s Student - gsnu200836


"FARAZ QURESHI" wrote:

Upon running the following code I get a message "Compile Error: Object
Required"

Sub FQCHECK()
Dim FQTEXT As String
Set FQTEXT = Application.InputBox(PROMPT:="Insert Keyword", Type:=2)
MsgBox ("YOU TYPED " & FQTEXT)
End Sub

While the following code executes perfectly:

Sub FQCHECK()
Dim FQRANGE As Range
Set FQRANGE = Application.InputBox(PROMPT:="SELECT CELL", Type:=8)
MsgBox ("YOU SELECTED " & FQRANGE.Address)
End Sub

What might be the cause? Is the Set statement only suitable for selection
range? Because the first piece of code works fine if entered as:
Sub FQCHECK()
Dim FQTEXT As String
FQTEXT = Application.InputBox(PROMPT:="Insert Keyword", Type:=2)
MsgBox ("YOU TYPED " & FQTEXT)
End Sub
--
Best Regards,
FARAZ A. QURESHI

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Is SET Statement only for Range?

You use the SET statement only for object-type variables. For basic
data types (strings, integers, longs, etc), you don't use SET. If you
don't use SET with an object-type variable, the compiler will attempt
to use the default value of the object

e.g.,
Dim R As Range
Set R = Range("A1") ' Set to assign object variable
R =1234 ' no set, uses default property "Value".

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 8 Mar 2009 13:24:01 -0700, FARAZ QURESHI
wrote:

Upon running the following code I get a message "Compile Error: Object
Required"

Sub FQCHECK()
Dim FQTEXT As String
Set FQTEXT = Application.InputBox(PROMPT:="Insert Keyword", Type:=2)
MsgBox ("YOU TYPED " & FQTEXT)
End Sub

While the following code executes perfectly:

Sub FQCHECK()
Dim FQRANGE As Range
Set FQRANGE = Application.InputBox(PROMPT:="SELECT CELL", Type:=8)
MsgBox ("YOU SELECTED " & FQRANGE.Address)
End Sub

What might be the cause? Is the Set statement only suitable for selection
range? Because the first piece of code works fine if entered as:
Sub FQCHECK()
Dim FQTEXT As String
FQTEXT = Application.InputBox(PROMPT:="Insert Keyword", Type:=2)
MsgBox ("YOU TYPED " & FQTEXT)
End Sub

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
IF statement with range JN Excel Worksheet Functions 3 August 27th 07 06:08 PM
IF STATEMENT Range Bee Excel Discussion (Misc queries) 5 July 30th 07 12:33 AM
range in an IF statement Dorothy J Excel Worksheet Functions 9 January 12th 07 08:44 PM
Use a range name in VB with IF Then Else statement spydor Excel Discussion (Misc queries) 1 January 6th 06 02:20 AM
IF Statement with a range Phillycheese5 Excel Worksheet Functions 8 July 28th 05 08:03 AM


All times are GMT +1. The time now is 03:28 PM.

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"