Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro problem


Can anyone tell me the problem with this macro, when run an error is
thrown and the returnAddress = MyCell.Address is highlighted.

Function returnAddress(rang As Range, source As String) As Range
For Each MyCell In rang
If MyCell = source Then
returnAddress = MyCell.Address
End If
Next MyCell
End Function


Thanks,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=501149

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Macro problem

Hi Tomski,

Try changing:

Function returnAddress(rang As Range, source As String) As Range


to

Function returnAddress(rang As Range, source As String) As String


---
Regards,
Norman



"Tomski" wrote in
message ...

Can anyone tell me the problem with this macro, when run an error is
thrown and the returnAddress = MyCell.Address is highlighted.

Function returnAddress(rang As Range, source As String) As Range
For Each MyCell In rang
If MyCell = source Then
returnAddress = MyCell.Address
End If
Next MyCell
End Function


Thanks,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile:
http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=501149



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro problem


Thats works, but the type is important, as I need to use the returned
variable in another function that has a Range for an argument.

If a string is returned then this function doesn't work.

Is it possible to type cast a string to a range?

Cheers,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=501149

  #4   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Macro problem

Instead of just "VARIABLE = New Value" format, you need to use the SET command

SET VARIABLE = NEW VALUE


"Tomski" wrote:


Thats works, but the type is important, as I need to use the returned
variable in another function that has a Range for an argument.

If a string is returned then this function doesn't work.

Is it possible to type cast a string to a range?

Cheers,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=501149


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Macro problem

Hi Tomski,

Try:

'=============
Function ReturnCell(rang As Range, SearchString As String) As Range
Dim MyCell As Range
For Each MyCell In rang
If MyCell.Value = SearchString Then
Set ReturnCell = MyCell
End If
Next MyCell
End Function
'<<=============

I changed ReturnAddress to ReturnCell because the former suggests, to me at
least, a string function. Similarly, I changed Source to SearchString
because the former suggests a range.

---
Regards,
Norman



"Tomski" wrote in
message ...

Thats works, but the type is important, as I need to use the returned
variable in another function that has a Range for an argument.

If a string is returned then this function doesn't work.

Is it possible to type cast a string to a range?

Cheers,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile:
http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=501149





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro problem


Thanks again, I will give it a try on monday and let you know how it
goes.

Cheers,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=501149

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
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Macro problem Jonah Excel Worksheet Functions 0 May 15th 05 09:13 PM
macro problem Kevin Excel Discussion (Misc queries) 1 December 14th 04 10:47 PM
Macro Problem Al Jager Excel Programming 0 January 28th 04 10:40 PM


All times are GMT +1. The time now is 02:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"