Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Range passed to a function - trying to just move through the range

I know this is a simple thing but I can't make the syntax work. I am passed a range into a
function that is 3 columns wide and some variable number of rows long.

The For loop is just trying to run through each of the rows in the range and pull the values
from the 3 columns in each row into variables to do some calculations.

Function WAR(Sel As Range) As Double

Y = Sel.Rows.Count

For i = 0 To (Y - 1)
A = Sel.Offset(i, 0).Value
B = Sel.Offset(i, 1).Value
C = Sel.Offset(i, 2).Value
Use values...
Next i
....

But this is not working. Can I not use Offset(x,y) to move around within the range Sel? If
not, now do I reference values at a given x,y coordinate within the range? Thanks.

John Black
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Range passed to a function - trying to just move through the range

John,
Change your code as shown, then you'll see why it's not working. You're not stepping thru each cell, you're selecting an offset to the whole range. Hope this helps,

regards,

Dave

Function WAR(Sel As Range) As Double
Y = Sel.Rows.Count

For i = 0 To (Y - 1)
Sel.Offset(i, 0).Select
Sel.Offset(i, 1).Select
Sel.Offset(i, 2).Select

' A = Sel.Offset(i, 0).Value
' B = Sel.Offset(i, 1).Value
' C = Sel.Offset(i, 2).Value
' Use values...

Next i
End Function
But this is not working. Can I not use Offset(x,y) to move around within the range Sel? If

not, now do I reference values at a given x,y coordinate within the range? Thanks.



John Black


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Range passed to a function - trying to just move through the range

Hi John,

Forgot to include a solution in previous post, this should do what you want.

regards,

Dave

Function WAR(Sel As Range) As Double

Y = Sel.Rows.Count

For i = 1 To Y
A = Sel(i, 1).Value
B = Sel(i, 2).Value
C = Sel(i, 3).Value

Next i
End Function


But this is not working. Can I not use Offset(x,y) to move around within the range Sel? If

not, now do I reference values at a given x,y coordinate within the range? Thanks.



John Black


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
Sum part of range passed to UDF [email protected] Excel Programming 5 August 4th 08 10:27 PM
dynamic range based on criteria, within a dynamic range, passed to a function [email protected] Excel Programming 5 October 9th 07 10:13 PM
Modify range variable passed through Function spyd3r Excel Programming 8 February 14th 06 11:22 PM
Excel2000: Reading values from range, passed to function as parameter using an expression Arvi Laanemets Excel Programming 3 April 29th 05 02:34 PM
Translate range name passed as string to a custom function to range addresses! agarwaldvk[_25_] Excel Programming 3 September 7th 04 12:47 PM


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