Vba formula to support range input

rossking

New Member
Joined
Jan 5, 2018
Messages
2
First I am not sure what it is called when you do below, so hard to search and see if there is a soultion.

What I am referring to is:


If you take a Raneg of cells and give them a name (Named Range)

ie THISAREA and it refers to A1:A20


then in B2:B20 you paste the same formula down

=If(THISAREA=1,"YES","NO")

Excel is smart enought to know this is a range of 20 cells, but I am only referring to the row that the formula is on.

So above on row 5 would evaluate only A5


How do i add that same logic to a VBA Function, Today if I apss same Range to function it wil fail as it gets the whole range and doesnt know what line to pull from



Function MyFunc(Data as variant) as variant

If Data = 1 then
MyFunc = "YES"
else
MyFunc = "NO"
end if

end Function

So i would do same as above but paste

=MyFunc(THISAREA)

and it will only work if THISAREA is a 1 cell range
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It really depends on what MyFunc does how you handle things if a range is passed to it.

For example, if you wanted to check if 'YES' appears in the range you could use a loop.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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