A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Check if variable is range



 
 
Thread Tools Display Modes
  #1  
Old May 7th, 2010, 09:08 PM posted to microsoft.public.excel.misc
Michiel via OfficeKB.com
external usenet poster
 
Posts: 20
Default Check if variable is range

This is probably very simple but I just don't see it.

How can I see if a (variant) variable is a range or something else (e.g. a
string)

Sub WhatIsIt()
Dim vrString As Variant
Dim vrRange1 As Variant
Dim vrRange2 As Variant


vrString = "This is a string"
Set vrRange1 = Range(Cells(1, 1), Cells(1, 2)) 'Note TWO cells included
Set vrRange2 = Range(Cells(1, 1), Cells(1, 1)) 'Note ONE cell included

'vrString.copy will not work since vrString is a string
'vrRange1.copy will work since vrRange1 is a range
'vrRange2.copy will work since vrRange1 is a range

'If isarray(vrString) then vrString.copy will work since vrString is not an
array
'If isarray(vrRange1) then vrRange1.copy will work since vrRange1 is an
array
'If isarray(vrRange2) then vrRange2.copy will work since vrRange2 is NOT an
array

End Sub

Any ideas?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/201005/1

  #2  
Old May 7th, 2010, 10:49 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default Check if variable is range

Maybe you could use:

MsgBox TypeName(vrString)
MsgBox TypeName(vrRange1)
MsgBox TypeName(vrRange2)

To see if that gives you want you need.

"Michiel via OfficeKB.com" wrote:

This is probably very simple but I just don't see it.

How can I see if a (variant) variable is a range or something else (e.g. a
string)

Sub WhatIsIt()
Dim vrString As Variant
Dim vrRange1 As Variant
Dim vrRange2 As Variant

vrString = "This is a string"
Set vrRange1 = Range(Cells(1, 1), Cells(1, 2)) 'Note TWO cells included
Set vrRange2 = Range(Cells(1, 1), Cells(1, 1)) 'Note ONE cell included

'vrString.copy will not work since vrString is a string
'vrRange1.copy will work since vrRange1 is a range
'vrRange2.copy will work since vrRange1 is a range

'If isarray(vrString) then vrString.copy will work since vrString is not an
array
'If isarray(vrRange1) then vrRange1.copy will work since vrRange1 is an
array
'If isarray(vrRange2) then vrRange2.copy will work since vrRange2 is NOT an
array

End Sub

Any ideas?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/201005/1


--

Dave Peterson
  #3  
Old May 10th, 2010, 02:12 PM posted to microsoft.public.excel.misc
Michiel via OfficeKB.com
external usenet poster
 
Posts: 20
Default Check if variable is range

Hi Dave,

I was right, it is indeed very simple.
Thank you very much. This will do!

M.

Dave Peterson wrote:
Maybe you could use:

MsgBox TypeName(vrString)
MsgBox TypeName(vrRange1)
MsgBox TypeName(vrRange2)

To see if that gives you want you need.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/201005/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:42 PM.


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