Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I calculate an offset between two ranges?

x and y are single column ranges of the same size. How do I retrieve
the corresponding values to x & from y as I loop through x? See
example below and thanks for any help.

Function offset(x As Range, y As Range, test As String)

For Each icell In x
If icell.Value = test Then
' I want to use the value of the corresponding element of range y here
End If
Next

End Function

--
Mo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How do I calculate an offset between two ranges?

Hi Mo,

Try something like,
'============
Function Myoffset(x As Range, y As Range, test As String)
Dim i As Long

If x.Count < y.Count Then Exit Function

For i = 1 To x.Count
With x(i)
If .Value = test Then .Value = y(i).Value
End With
Next
End Function
'============

---
Regards,
Norman



"mo childs" wrote in message
...
x and y are single column ranges of the same size. How do I retrieve
the corresponding values to x & from y as I loop through x? See
example below and thanks for any help.

Function offset(x As Range, y As Range, test As String)

For Each icell In x
If icell.Value = test Then
' I want to use the value of the corresponding element of range y here
End If
Next

End Function

--
Mo



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default How do I calculate an offset between two ranges?

Hi

When all values in x are unique, then simply:
ReturnValue=Application.WorksheetFunction.VLookup( icell,x:y,2,0)

NB! offset is built-in function, so don't use it as an UDF name! When values
in x aren't unique, then:

Function YourFunc(x As Range, y As Range, test As String)
YourFunc = ""
i = 0
For Each icell In x
i = i + 1
If icell.Value = test Then YourFunc = y(i)
Next
End Function


Arvi Laanemets


"mo childs" wrote in message
...
x and y are single column ranges of the same size. How do I retrieve
the corresponding values to x & from y as I loop through x? See
example below and thanks for any help.

Function offset(x As Range, y As Range, test As String)

For Each icell In x
If icell.Value = test Then
' I want to use the value of the corresponding element of range y here
End If
Next

End Function

--
Mo



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I calculate an offset between two ranges?


Offset = Range("B5:B9").Column - Range("D5:D9").Column

Kaa

--
Kaa
-----------------------------------------------------------------------
Kaak's Profile: http://www.excelforum.com/member.php...nfo&userid=751
View this thread: http://www.excelforum.com/showthread.php?threadid=47742

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I calculate an offset between two ranges?

That's just what I wanted. Thanks very much

Kaak wrote:

Offset = Range("B5:B9").Column - Range("D5:D9").Column



--
Mo


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
Dynamic Ranges and Offset RFJ Excel Worksheet Functions 3 August 29th 06 03:20 PM
Offset function and Dynamic Ranges SandyLACA Excel Discussion (Misc queries) 2 August 2nd 06 11:07 PM
Using Offset with named ranges StanJ Excel Worksheet Functions 5 September 2nd 05 09:07 AM
Macro showing Offset instead of Ranges Diane Thorpe Excel Programming 2 June 6th 05 09:03 PM
Ranges using offset Fatir Zelen Excel Programming 11 April 24th 04 11:15 PM


All times are GMT +1. The time now is 06:48 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"