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: 470
Default Defining a variable range

How do you reference a range that changes based on user input?

I have Worksheet("PCEMS") that has my work schedule for each year starting
with 2006. Each schedule is 52 rows and offset from beginning of one year to
beginning of next year is 58 rows.

How do you reference a range that changes based on user input?

I ask user (me) for year via Inputbox. I take the answer and perform
following calculation: yrdiff = yr - 2006 This gives me an offset factor.

I want to reference data in column O depending on year entered.
2006 (2006-2006 = factor of 0) = RANGE("O8:O59")
2007 (2007-2006 = factor of 1) = RANGE("O67:O117")
2008 (2008-2006 = factor of 2) = RANGE("O124:O175")

Since the range is based on what year the user enters, I need to know how to
reference the range. I know this is not the correct format, but you will see
how I use the factor. I will use 2006 as yr and yrdiff = (2006-2006) for
factor of 0.

begrng = Worksheets("PCEMS").Cells(8+(58*yrdiff),15)
endrng = begrng.Offset(59 + (58 * yrdiff), 0)

How can I get the begrng and endrng to be one like Range("O8:O59) so that I
can execute a "For Each Cell In Range _______" loop?

Thanks,
Les
 
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
Defining a Dynamic Range using a variable Alseikhan[_4_] Excel Programming 3 March 27th 06 08:56 AM
Defining a variable Range for cells with values in them! John Baker Excel Programming 1 January 19th 05 02:04 PM
Defining a Variable Range Dave Peterson[_5_] Excel Programming 0 January 19th 05 02:30 AM
Defining a variable within a sub... aking1987[_3_] Excel Programming 1 November 11th 04 01:12 PM
Defining a variable within a sub... aking1987[_2_] Excel Programming 1 November 11th 04 12:32 PM


All times are GMT +1. The time now is 01:31 PM.

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"