Error 438 and Union function

eviMogwai

New Member
Joined
Jul 4, 2011
Messages
26
Hello =)

I am trying to make a function to compare a range with a subset of itself.
Depending on the length of the input, I need to take off a different amount of cells from the ends. Luckily there is only about three possible lengths that can get this far into the function.

So one way I've figured is put the input through a loop, pick the interesting parts and add them together in a new range with the Union function

Code:
function foo(rLevels as Range)
'-- rLevels is at least 16 cells
 
'-- code goes here
 
'-- init as Union doesn't handle empty ranges
Set rMyLevels = rLevels(4)
 
    For i = 1 To rLevels.Cells.Count
        If i > 4 And i < 20 Then
           Set rMyLevels = Application.WorksheetFunction.Union(rMyLevels, rLevels.Cells(i))
        End If
        Next

I have deliberately put in 2 different ways of referring to a cell,
rLevels(4) and rLevels.Cells(i), with hope that someone could tell me which one is right, both return the value, but what type is it?

When I run the code (with consistent referencing), i get error '438' Object Doesn't Support This Property Or Method.
Any ideas?


This is a repost of a spin-off of my post at: http://www.mrexcel.com/forum/newreply.php?do=newreply&p=2819179
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Union is not a worksheet function.
 
Upvote 0
Union isn't a worksheet function.
Try

Code:
Set rMyLevels = Union(rMyLevels, rLevels.Cells(i))
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top