PC Review


Reply
Thread Tools Rate Thread

Call back a Dim variable

 
 
=?Utf-8?B?Q2hyaXMgVC1N?=
Guest
Posts: n/a
 
      11th Nov 2007
I really feel stupid on this one, but it's 4am here, so maybe you'll cut me
some slack.

Code:
Dim CrntA As String
CrntA = Range("A41").Select
[some stuff]
Range("CrntA").Select

Issue:
I want to return to A41 using the variable, so I can change the variable and
loop the code, but try as I might, my Range.Select method isn't taking me
anywhere.

Error Code: (approximately)
Run-time error '1004'
Method 'Range' of object '_Global' failed

Question:
How do I properly set up a variable, and use it to return to the cell I used
as the variable.

Hope someones out there early on a Sunday. Thanks in advance.


 
Reply With Quote
 
 
 
 
Helmut Weber
Guest
Posts: n/a
 
      11th Nov 2007
Hi Chris,

maybe like that:

Dim D4 As Range
Set D4 = Range("D4") ' or any other
' do something
D4.Select

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA (not ExcelVBA, for sure)

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


 
Reply With Quote
 
=?Utf-8?B?RlN0MQ==?=
Guest
Posts: n/a
 
      11th Nov 2007
hi
Dim Crnta as range
set Crnta = range("A41")
'some stuff
Crnta.select

works for me. using xp & 03
regards
FSt1

"Chris T-M" wrote:

> I really feel stupid on this one, but it's 4am here, so maybe you'll cut me
> some slack.
>
> Code:
> Dim CrntA As String
> CrntA = Range("A41").Select
> [some stuff]
> Range("CrntA").Select
>
> Issue:
> I want to return to A41 using the variable, so I can change the variable and
> loop the code, but try as I might, my Range.Select method isn't taking me
> anywhere.
>
> Error Code: (approximately)
> Run-time error '1004'
> Method 'Range' of object '_Global' failed
>
> Question:
> How do I properly set up a variable, and use it to return to the cell I used
> as the variable.
>
> Hope someones out there early on a Sunday. Thanks in advance.
>
>

 
Reply With Quote
 
SteveM
Guest
Posts: n/a
 
      11th Nov 2007
The problem is the Select method. Select returns "True" not the
Address. Use Address instead. i.e.

Dim strAdd as String
strAdd = Range("A41").Address
' some code
strAdd = Range(str).Select

You could also simply use a Range variable. i.e.

Dim rngVar as Range
Set rngVar = Range("A41")
'some code
rngVar.Select

* note the Set statement for assigning the Range variable

SteveM




On Nov 11, 7:28 am, Chris T-M <Chri...@discussions.microsoft.com>
wrote:
> I really feel stupid on this one, but it's 4am here, so maybe you'll cut me
> some slack.
>
> Code:
> Dim CrntA As String
> CrntA = Range("A41").Select
> [some stuff]
> Range("CrntA").Select
>
> Issue:
> I want to return to A41 using the variable, so I can change the variable and
> loop the code, but try as I might, my Range.Select method isn't taking me
> anywhere.
>
> Error Code: (approximately)
> Run-time error '1004'
> Method 'Range' of object '_Global' failed
>
> Question:
> How do I properly set up a variable, and use it to return to the cell I used
> as the variable.
>
> Hope someones out there early on a Sunday. Thanks in advance.



 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      11th Nov 2007
Thsi is one way

=Myfunction(A110)

Sub MyFunction(Target as Range)

MyFunction = 0
for each cell in Target
MyFunction = MyFunction + cell.value
end sub

"Chris T-M" wrote:

> I really feel stupid on this one, but it's 4am here, so maybe you'll cut me
> some slack.
>
> Code:
> Dim CrntA As String
> CrntA = Range("A41").Select
> [some stuff]
> Range("CrntA").Select
>
> Issue:
> I want to return to A41 using the variable, so I can change the variable and
> loop the code, but try as I might, my Range.Select method isn't taking me
> anywhere.
>
> Error Code: (approximately)
> Run-time error '1004'
> Method 'Range' of object '_Global' failed
>
> Question:
> How do I properly set up a variable, and use it to return to the cell I used
> as the variable.
>
> Hope someones out there early on a Sunday. Thanks in advance.
>
>

 
Reply With Quote
 
=?Utf-8?B?Q2hyaXMgVC1N?=
Guest
Posts: n/a
 
      11th Nov 2007
That worked perfectly.

I suppose this issue was just to remind me that the little things count. Oh,
and sleep helps too.

Thank you very much for the quick response.
Chris McCune

"Helmut Weber" wrote:

> Hi Chris,
>
> maybe like that:
>
> Dim D4 As Range
> Set D4 = Range("D4") ' or any other
> ' do something
> D4.Select
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA (not ExcelVBA, for sure)
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use a variable to call a variable preiously set. Richhall Windows XP General 8 19th Sep 2008 03:34 PM
Call a Private Sub using a variable Caezar Microsoft Excel Programming 3 4th May 2008 02:47 PM
One variable can call many form khokimfang@gmail.com Microsoft VB .NET 2 3rd Aug 2006 04:19 AM
call a sub using a variable =?Utf-8?B?c21rMjM=?= Microsoft Access VBA Modules 10 28th Jun 2005 06:48 PM
Call dll in variable location =?Utf-8?B?U3ZlbiBEYWVtcw==?= Microsoft Access VBA Modules 3 13th Jun 2005 07:18 PM


Features
 

Advertising
 

Newsgroups
 


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