<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Public Variable Accessed by Function? in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050011#M23740</link>
    <description>Hi NSL!&lt;BR /&gt;
&lt;BR /&gt;
Your Problem is that 'Range' is not a type of variable used by AutoCAD but &lt;BR /&gt;
only used by Excel.&lt;BR /&gt;
So AutoCAD can't initialize! So use Type Variant and then you succeed.&lt;BR /&gt;
&lt;BR /&gt;
BERNIE&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;NSL22&gt; wrote in message news:5696790@discussion.autodesk.com...&lt;BR /&gt;
'I have a public variable:&lt;BR /&gt;
Public RefZone1Rng As Range&lt;BR /&gt;
&lt;BR /&gt;
'That I set in a Sub:&lt;BR /&gt;
Sub CheckZones()&lt;BR /&gt;
Set RefZone1Rng = Refwrksht.Range(Refwrksht.Cells(2, 1), &lt;BR /&gt;
Refwrksht.Cells(RefZone1_Bot, 1))&lt;BR /&gt;
&lt;BR /&gt;
'That I would like to be available to a Function that I pass some variables &lt;BR /&gt;
to within the first sub:&lt;BR /&gt;
ColorNum = Search_ref_zone(Choice, BZone)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'The following is the function that I go to. I would like it to recognize &lt;BR /&gt;
that RefZone1Rng has been declaired in the procedure above without having to &lt;BR /&gt;
pass it the variables explicitely.&lt;BR /&gt;
Function Search_ref_zone(RefZone As Integer, BZone As String)&lt;BR /&gt;
    Dim SelRange As Range&lt;BR /&gt;
    Select Case RefZone&lt;BR /&gt;
        Case 1&lt;BR /&gt;
            SelRange = RefZone1Rng&lt;BR /&gt;
        End Select&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
'Is this possible?  Thank you!&lt;/NSL22&gt;</description>
    <pubDate>Wed, 22 Aug 2007 06:33:28 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2007-08-22T06:33:28Z</dc:date>
    <item>
      <title>Public Variable Accessed by Function?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050010#M23739</link>
      <description>'I have a public variable:&lt;BR /&gt;
Public RefZone1Rng As Range&lt;BR /&gt;
&lt;BR /&gt;
'That I set in a Sub:&lt;BR /&gt;
Sub CheckZones()&lt;BR /&gt;
Set RefZone1Rng = Refwrksht.Range(Refwrksht.Cells(2, 1), Refwrksht.Cells(RefZone1_Bot, 1))&lt;BR /&gt;
&lt;BR /&gt;
'That I would like to be available to a Function that I pass some variables to within the first sub:&lt;BR /&gt;
ColorNum = Search_ref_zone(Choice, BZone)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'The following is the function that I go to. I would like it to recognize that RefZone1Rng has been declaired in the procedure above without having to pass it the variables explicitely.  &lt;BR /&gt;
Function Search_ref_zone(RefZone As Integer, BZone As String)&lt;BR /&gt;
    Dim SelRange As Range&lt;BR /&gt;
    Select Case RefZone&lt;BR /&gt;
        Case 1&lt;BR /&gt;
            SelRange = RefZone1Rng&lt;BR /&gt;
        End Select&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
'Is this possible?  Thank you!</description>
      <pubDate>Tue, 21 Aug 2007 21:25:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050010#M23739</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-21T21:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Public Variable Accessed by Function?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050011#M23740</link>
      <description>Hi NSL!&lt;BR /&gt;
&lt;BR /&gt;
Your Problem is that 'Range' is not a type of variable used by AutoCAD but &lt;BR /&gt;
only used by Excel.&lt;BR /&gt;
So AutoCAD can't initialize! So use Type Variant and then you succeed.&lt;BR /&gt;
&lt;BR /&gt;
BERNIE&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;NSL22&gt; wrote in message news:5696790@discussion.autodesk.com...&lt;BR /&gt;
'I have a public variable:&lt;BR /&gt;
Public RefZone1Rng As Range&lt;BR /&gt;
&lt;BR /&gt;
'That I set in a Sub:&lt;BR /&gt;
Sub CheckZones()&lt;BR /&gt;
Set RefZone1Rng = Refwrksht.Range(Refwrksht.Cells(2, 1), &lt;BR /&gt;
Refwrksht.Cells(RefZone1_Bot, 1))&lt;BR /&gt;
&lt;BR /&gt;
'That I would like to be available to a Function that I pass some variables &lt;BR /&gt;
to within the first sub:&lt;BR /&gt;
ColorNum = Search_ref_zone(Choice, BZone)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'The following is the function that I go to. I would like it to recognize &lt;BR /&gt;
that RefZone1Rng has been declaired in the procedure above without having to &lt;BR /&gt;
pass it the variables explicitely.&lt;BR /&gt;
Function Search_ref_zone(RefZone As Integer, BZone As String)&lt;BR /&gt;
    Dim SelRange As Range&lt;BR /&gt;
    Select Case RefZone&lt;BR /&gt;
        Case 1&lt;BR /&gt;
            SelRange = RefZone1Rng&lt;BR /&gt;
        End Select&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
'Is this possible?  Thank you!&lt;/NSL22&gt;</description>
      <pubDate>Wed, 22 Aug 2007 06:33:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050011#M23740</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-22T06:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Public Variable Accessed by Function?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050012#M23741</link>
      <description>Bernie, that's not it....&lt;BR /&gt;
&lt;BR /&gt;
It is simply that an Excel 'Range' is an object, not a variable, so you have to...&lt;BR /&gt;
&lt;BR /&gt;
SET SelRange = RefZone1Rng&lt;BR /&gt;
&lt;BR /&gt;
Cheers,&lt;BR /&gt;
Dave</description>
      <pubDate>Wed, 22 Aug 2007 10:33:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050012#M23741</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-22T10:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: Public Variable Accessed by Function?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050013#M23742</link>
      <description>Also, if this code is running inside AutoCAD, its probably a good idea to at least partially specify objects from other applications e.g. Excel.Range, rather than just Range.  If somebody else has to work on the code, they don't have to scratch their head about what a Range object is.</description>
      <pubDate>Wed, 22 Aug 2007 15:46:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050013#M23742</guid>
      <dc:creator>dgorsman</dc:creator>
      <dc:date>2007-08-22T15:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Public Variable Accessed by Function?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050014#M23743</link>
      <description>Blast... It still doesn't work.  It at least recognizes RefZone1Rng in the 2nd procedure though.  &lt;BR /&gt;
&lt;BR /&gt;
It successfully sets the range in the Check_Zones procedure, but once ownership goes to the Search_ref_Zone procedure, the RefZone1Rng range goes to nothing.  &lt;BR /&gt;
&lt;BR /&gt;
It doesn't make any sense...  &lt;BR /&gt;
Anyways, Thanks SysRq for the help!  Thanks everyone else too!</description>
      <pubDate>Wed, 22 Aug 2007 20:23:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050014#M23743</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-22T20:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Public Variable Accessed by Function?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050015#M23744</link>
      <description>My bad.  I figured it out.  I accidentally Double defined the public ranges.  Once outside of the procedures.  Then 2nd, inside the first procedure.  &lt;BR /&gt;
&lt;BR /&gt;
Cool beans.  Thanks again!</description>
      <pubDate>Wed, 22 Aug 2007 21:17:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/public-variable-accessed-by-function/m-p/2050015#M23744</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-22T21:17:46Z</dc:date>
    </item>
  </channel>
</rss>

