LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default returning ranges offset from argument range function call

Hi Everyone,
I'm new to VBA, so please pardon if this is a silly question. I have
some named ranges (e.g. DATES) and I'd like to have a function with an
integer argument and a range argument that returns a subrange of the
argument range. For the full code there will be two ranges so that
just what occured on those dates is the returned range. Here are some
examples of the way that I've been trying to do this and some of the
errors that I've been able to see the code making. I'd like to know
if there is a standard way of doing this. I think I can hack up
something with sheet formula, but I would prefer to have a working
function for a little more flexiblity. Don't know if this will get me
flamed, but I am using the OS X version of excel, in case that info is
important.

Option Explicit

'test works as expected
Function test1(arg As Integer, dat As Range) As Range

Set test1 = dat.Offset(arg, 0)
End Function

'test works as expected
Function test2(arg As Integer, dat As Range) As Range

Set test2 = dat.Cells(arg + 1, 1)
End Function

'doesn't work as expected (i.e. doesn't return dat(arg:(arg + 1))
Function test3(arg As Integer, dat As Range) As Range

Set test3 = dat.Range(dat.Cells(arg + 1, 1), dat.Cells(arg + 2, 1))
End Function

'doesn't work as expected (returns something in the column I want, but
rows are messed up
'offset in dat returned is sheet offset where dat is stored from dat
start + the offset that I add

Function test4(arg As Integer, dat As Range) As Range

Set test4 = dat.Range(dat.Cells(arg + 1, 0), dat.Cells(arg + 2, 0))
End Function

Function test5(arg As Integer, dat As Range) As Range

Set test5 = dat(dat.Cells(arg + 1, 1), dat.Cells(arg + 2, 1))
End Function

Anyhelp is appreciated, thanks in advance.
 
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
Function argument not returning a value Linda Excel Worksheet Functions 11 December 28th 07 11:38 PM
OFFSET function in named range returning wrong # of rows Heidi Excel Worksheet Functions 5 March 20th 07 10:15 PM
Offset function and Dynamic Ranges SandyLACA Excel Discussion (Misc queries) 2 August 2nd 06 11:07 PM
OFFSET function returning #VALUE when using external references AndrewPace Excel Worksheet Functions 2 April 12th 06 06:37 PM
Range as argument in function Asif[_3_] Excel Programming 3 December 6th 03 01:38 PM


All times are GMT +1. The time now is 08:03 AM.

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"