Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Call back a Dim variable

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default Call back a Dim variable

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"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Call back a Dim variable

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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Call back a Dim variable

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
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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Call back a Dim variable

Thsi is one way

=Myfunction(A1:D10)

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.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Call back a Dim variable

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
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
How can I call IE browser (Back button) through Excel macro? SAM SEBAIHI Excel Discussion (Misc queries) 0 December 14th 06 12:49 AM
How can I call IE browser (Back button) through Excel macro? SAM SEBAIHI Excel Discussion (Misc queries) 0 December 13th 06 04:50 AM
A 64-bit variable from VBA to VC++ dll and back to VBA [email protected] Excel Programming 0 July 4th 06 12:49 PM
clipboard forgets on call back Ernesto[_2_] Excel Programming 0 July 6th 04 07:44 PM
Using variable to call worksheets Calypsoblur Excel Programming 3 November 8th 03 10:47 PM


All times are GMT +1. The time now is 05:24 AM.

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"