LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Look up range and return value

This looks basically like what I want to do, except I need to do it multiple
times at once. I'll try to explain.

I have a weight in cell Sheet1 D11

Sheet2 is a table. Columns A & B are min and max values for a range of
weights. So A1 is 0, B1 is 2.5. A2 is 2.6, B2 is 5. On and on. Column C
is a dollar amount based on that weight. So for row 1 (range 0 - 2.5) the
charge is $1.00. Column D is another dollar amount for each range, so row 1
the charge is $1.50. This repeats for Columns E, F, G. I have 5 zones for
each weight range.

Back on Sheet1 I again have 5 zones. I want the freight cell for each zone
to refer to the table on Sheet2 and extract the appropriate charge (Columns
C, D, E, F, or G) based on the weight indicated in cell D11.

Does that make sense?


"ker_01" wrote:

mthead-

Here is a framework to get you started- feel free to post back if you have
trouble adapting this to your needs (and see comments below).

1. You will probably find it easier to either put your reference range in
the same workbook, or if that isn't an option, at least have the workbook
containing the reference range open anytime you open a workbook where you
need to calculate these values. This code hardcodes your source range for
convenience.

2. This code assumes that you will be using numeric values only for your
comparisons. If you have any numbers stored as text, etc, expect it to return
an error.

3. You didn't specify what you wanted to do with overlapping ranges, so I
assumed which case would be = vs <=. Feel free to change that if appropriate.

Open the VBE, copy/paste this into a new module. Then in your worksheet, you
can use it just like any other formula
=ReturnNewValue(A1) where cell A1 would contain your target value.

Code: (watch for linewrap)

Function ReturnNewValue(IValue)

Dim CompareRange As Variant
CompareRange = Sheet1.Range("A1:C150") '<-change this to your actual source
range

For p = LBound(CompareRange) To UBound(CompareRange)
If IValue = CompareRange(p, 1) And IValue < CompareRange(p, 2) Then
ReturnNewValue = CompareRange(p, 3)
Next

End Function

"mthead" wrote:

What I need to do:

Using Value "A" (let's say 20), lookup on on a table and find the row that
20 falls in the range of column A and column B (let's say column A is 15 and
column B is 25) i want to return the value of column C in the same row.
There is a possibility of 150 different rows. Also, value A is in workbook
Jobs, and the table is in workbork Tables.

Any expertise would be appreciated.



 
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
how to return a range NDBC Excel Programming 2 September 4th 09 06:13 AM
Return date if in range, else return blank LisaL Excel Worksheet Functions 1 July 22nd 09 03:23 PM
drop first row in range and return a new range object Rik Excel Programming 1 November 19th 08 10:12 AM
Return Range Address from Active Range ExcelMonkey Excel Programming 1 February 10th 06 12:00 PM
Return Range in VB ray Excel Programming 4 December 11th 03 08:12 PM


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