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

Can anyone help me simplify the following function? The object references
seem too complicated (eg ActiveSheet.Range(area1.Address).Cells )
and I can't get the output bit to work.

Any ideas?

Thanks


Damien



Public Function CrossJoin(area1 As Range, area2 As Range, Optional
output_range)
'Cartesian Join two areas

'On Error GoTo CrossJoin_Err

Dim cll1
Dim cll2
Dim i As Long

For Each cll1 In ActiveSheet.Range(area1.Address).Cells
For Each cll2 In ActiveSheet.Range(area2.Address).Cells

Debug.Print cll1, cll2

If Not IsMissing(output_range) Then

'!!TODO
ActiveSheet.Range(output_range.Address).Value = cll1.Value

End If

i = i + 1
Next
Next

CrossJoin = i

CrossJoin_Exit:

Exit Function

CrossJoin_Err:

MsgBox Err & ", " & Err.Description

Resume CrossJoin_Exit

End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Simplify CrossJoin function

since you are passing in area1 and area1 and output as ranges they already
know what sheet they are on.


Public Function CrossJoin(area1 As Range, area2 As Range, Optional
output_range)
'Cartesian Join two areas

'On Error GoTo CrossJoin_Err

Dim cll1 as Range
Dim cll2 as Range
Dim i As Long

For Each cll1 In area1.Cells
For Each cll2 In area2.Cells

Debug.Print cll1, cll2

If Not IsMissing(output_range) Then

'!!TODO
output_range.Value = cll1.Value

End If

i = i + 1
Next
Next

CrossJoin = i

CrossJoin_Exit:

Exit Function

CrossJoin_Err:

MsgBox Err & ", " & Err.Description

Resume CrossJoin_Exit

End Function


Not sure what a cartesion join is, but perhaps you want the intersection or
the union

On error resume next
set rng = intersect(area1,area2)
On Error goto 0
set output_range = rng

--
Regards,
Tom Ogilvy



"Damien" wrote in message
...
Can anyone help me simplify the following function? The object references
seem too complicated (eg ActiveSheet.Range(area1.Address).Cells )
and I can't get the output bit to work.

Any ideas?

Thanks


Damien



Public Function CrossJoin(area1 As Range, area2 As Range, Optional
output_range)
'Cartesian Join two areas

'On Error GoTo CrossJoin_Err

Dim cll1
Dim cll2
Dim i As Long

For Each cll1 In ActiveSheet.Range(area1.Address).Cells
For Each cll2 In ActiveSheet.Range(area2.Address).Cells

Debug.Print cll1, cll2

If Not IsMissing(output_range) Then

'!!TODO
ActiveSheet.Range(output_range.Address).Value = cll1.Value

End If

i = i + 1
Next
Next

CrossJoin = i

CrossJoin_Exit:

Exit Function

CrossJoin_Err:

MsgBox Err & ", " & Err.Description

Resume CrossJoin_Exit

End Function



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
Custom function to simplify Index(match)) formula Martin Excel Discussion (Misc queries) 0 March 20th 06 02:45 PM
Help me simplify this function.... killertofu Excel Worksheet Functions 6 February 15th 06 01:46 PM
simplify a vlookup function Caveman Excel Worksheet Functions 1 September 26th 05 03:39 PM
simplify function Luke Excel Worksheet Functions 13 May 3rd 05 02:07 AM
Simplify Vlookup function in Excel Budman Excel Worksheet Functions 7 March 27th 05 04:17 PM


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