Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Offsetting a Range


Here's what I have so far:

Lvalue = Sheets("Historical Load").Range("A2").Value
Set IRange = Sheets("Historical Load").Range("C1:BA1").Offset(i - 1,
0)
Set Vrange = Sheets("Historical Load").Range("C8:BA8")
Set MyCell = Sheets("Nomination").Range("H1")
MyCell.Offset(i - 1, 0).Value = Application.WorksheetFunction.index _
(IRange, 1, Application.WorksheetFunction.Match(Lvalue, Vrange,
False))

This is part of a For - Next loop, where i is an integer.

In that second row, I want to Offset that entire range ("C1:BA1") by the
amount i - 1.

I think it's not working because Offset is usually for a single cell. Does
anyone have any suggestions for getting this to work?

Thanks!

Alex
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Offsetting a Range


it looks like it's doing what you want:

type or paste these 3 lines in the immediate window , pressing enter after each
one, and see what the range is for irange

i =5
Set IRange = Sheets("Historical Load").Range("C1:BA1").Offset(i - 1,0)
?irange.address

then change the value of i and try again.

immediate window is accessed by Control-G or view/immediate window from the menu
in the vb editor


--


Gary

"awright" wrote in message
...

Here's what I have so far:

Lvalue = Sheets("Historical Load").Range("A2").Value
Set IRange = Sheets("Historical Load").Range("C1:BA1").Offset(i - 1,
0)
Set Vrange = Sheets("Historical Load").Range("C8:BA8")
Set MyCell = Sheets("Nomination").Range("H1")
MyCell.Offset(i - 1, 0).Value = Application.WorksheetFunction.index _
(IRange, 1, Application.WorksheetFunction.Match(Lvalue, Vrange,
False))

This is part of a For - Next loop, where i is an integer.

In that second row, I want to Offset that entire range ("C1:BA1") by the
amount i - 1.

I think it's not working because Offset is usually for a single cell. Does
anyone have any suggestions for getting this to work?

Thanks!

Alex



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Offsetting a Range

It depends on what you I value is. If I - 1 is negative you will fail
because you rows start at 1. Offsetting Row 1 by -1 will get Row 0 which
will create an error.

"awright" wrote:


Here's what I have so far:

Lvalue = Sheets("Historical Load").Range("A2").Value
Set IRange = Sheets("Historical Load").Range("C1:BA1").Offset(i - 1,
0)
Set Vrange = Sheets("Historical Load").Range("C8:BA8")
Set MyCell = Sheets("Nomination").Range("H1")
MyCell.Offset(i - 1, 0).Value = Application.WorksheetFunction.index _
(IRange, 1, Application.WorksheetFunction.Match(Lvalue, Vrange,
False))

This is part of a For - Next loop, where i is an integer.

In that second row, I want to Offset that entire range ("C1:BA1") by the
amount i - 1.

I think it's not working because Offset is usually for a single cell. Does
anyone have any suggestions for getting this to work?

Thanks!

Alex

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Offsetting a Range

Thank you! You were completely right.

I gave it a good i and now it's working, but now of course another part isn't:

The last line:

MyCell.Offset(i - 1, 0).Value = Application.WorksheetFunction.index _
(IRange, 1, Application.WorksheetFunction.Match(Lvalue, Vrange,
False))

comes up with the error message: "Unable to get the Match property of the
WorksheetFunction class"

This is my first time using a WorksheetFunction, so I'm not sure what this
means.

Thanks for your help!

Alex

"Gary Keramidas" wrote:

it looks like it's doing what you want:

type or paste these 3 lines in the immediate window , pressing enter after each
one, and see what the range is for irange

i =5
Set IRange = Sheets("Historical Load").Range("C1:BA1").Offset(i - 1,0)
?irange.address

then change the value of i and try again.

immediate window is accessed by Control-G or view/immediate window from the menu
in the vb editor


--


Gary

"awright" wrote in message
...

Here's what I have so far:

Lvalue = Sheets("Historical Load").Range("A2").Value
Set IRange = Sheets("Historical Load").Range("C1:BA1").Offset(i - 1,
0)
Set Vrange = Sheets("Historical Load").Range("C8:BA8")
Set MyCell = Sheets("Nomination").Range("H1")
MyCell.Offset(i - 1, 0).Value = Application.WorksheetFunction.index _
(IRange, 1, Application.WorksheetFunction.Match(Lvalue, Vrange,
False))

This is part of a For - Next loop, where i is an integer.

In that second row, I want to Offset that entire range ("C1:BA1") by the
amount i - 1.

I think it's not working because Offset is usually for a single cell. Does
anyone have any suggestions for getting this to work?

Thanks!

Alex




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
Offsetting Dan Wood Excel Discussion (Misc queries) 3 March 3rd 10 03:23 PM
Offsetting and HLOOKUP KellyB Excel Worksheet Functions 5 January 29th 08 07:09 PM
Cont'd - Offsetting within a range dynamically - But returning a sum of all instances criteria are met S Davis Excel Worksheet Functions 1 July 28th 06 03:37 PM
Offsetting Cells PGalla06 Excel Programming 1 June 13th 05 11:28 PM
Offsetting a varible?? Ashley Milford via OfficeKB.com Excel Programming 5 June 2nd 05 03:38 PM


All times are GMT +1. The time now is 04:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"