473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I get excel to show a specific answer for a number falling between two points?

I am trying to create a spreadsheet for use in Pavement Design. I need a formula that can pick up what answer is required when the user types in a specific number.

For example: If the traffic count is between 100-299 then I want 98 to appear in the answer box, however if the traffic count is between 300-599 then I want 97 to appear. There are loads of these that go up in 200's then 10,000 (approximatley 23 possible answers!) any help would be greatly appreciated!

Em
Sep 20 '10 #1
9 1791
Mariostg
332 100+
A "quick" and dirty way would be to fill in a sheet with all the possible traffic count and beside it the answer:
100 98
101 98
...
300 97
301 97

etc.
Then use VLOOKUP to get the "answer"
Sep 20 '10 #2
Cheers, but it's for work and the traffic count data goes up to 100,000, could be a massive sheet!! Is there any other way?
Sep 20 '10 #3
Mariostg
332 100+
Oh I see, then this is not a good option.
You probably want to do that in VBA then and activate the selection through a button. Basic idea is like this:

Expand|Select|Wrap|Line Numbers
  1. x = Cells(1, 1)
  2. Select Case x
  3.     Case 100 - 299
  4.         a = 23
  5.     Case 300 - 400
  6.         a = 34
  7.     Case Else
  8.         a = 0
  9. End Select
  10.  
Sep 20 '10 #4
OldBirdman
675 512MB
I would create another worksheet (tab) with these values. ColumnA would be upper limit, Column B the desired answer.
Expand|Select|Wrap|Line Numbers
  1.    A      B
  2.    0      0
  3.   99     99
  4.  299     98
  5.  599     97
  6. ....
  7. 9999     66
I would write a VBA function to check each row, from 2 until ColumnA is blank. When the test value exceeds ColumnA, return the answer in ColumnB, row = Current - 1.

This would make it easy to maintain. You would probably want to re-sort before checking, and also error check the input to function.
Sep 20 '10 #5
NeoPa
32,556 Expert Mod 16PB
You want VLookup() Em. If the fourth parameter is set as TRUE then it treats the table as an ordered list and finds the closest match upwards.

The attachment includes a Word document that covers this in detail.
Attached Files
File Type: zip VLookUp.Zip (35.8 KB, 101 views)
Sep 20 '10 #6
NeoPa
32,556 Expert Mod 16PB
For those not wanting to look at the attachment the main contents of this are as below. The attachment does have some examples shown though, so may be worth the effort. Also, the text contains references to the diagrams which are less useful without them of course.

VLookUp(A, B, C, D)

VlookUp or Vertical LookUp is a function that enables Excel to ‘Find’ related items from within a range stored elsewhere. Elsewhere can mean another excel workbook on another PC, but can also mean a range in the current worksheet.
In any Range reference in Excel, a ’$’ preceeding an element of the address, simply tells Excel not to be clever when copying or dragging the formula to other cells. Notice the formulas displayed in column B below: First B1 is created, then that cell is copied and pasted, or dragged down over, the other cells. Notice the only item that changes is the number (Row reference) after $A.
  1. This is the item to search for and is often a cell reference. The ‘$’ is usually required here for the column letter but rarely for the Row number.
  2. This is a reference to the range being searched. This is almost always fully referenced with ‘$’s.
    If it is a requirement to refer to ranges in other worksheets or even other workbooks, the format for each of these is illustrated in cells E1 & E3 below respectively. For space reasons, the range in Book2 starts at B3 rather than at E5, but ‘[Book1]Sheet 2’ has the data in the same place as Sheet1 (E5:F9). Basically, a worksheet reference preceeds the cell part with a ‘!’ separating them. Any complicated name (reserved word or containing unusual characters including spaces) requires singe quotes (‘) around it – Sheet2!$A$1:$C$9 but ‘Sheet 2’!$A$1:$C$9. A workbook reference preceeds the worksheet reference and is surrounded in [] brackets. If (‘)s required in sheet name then the workbook reference follows the first (‘) – ‘[Book2]Sheet 2’!$A$1:$C$9.
  3. This is the column to display if a match is found. In the example below, the words (Abacus; Broadcast; …) are found in column F, but in column 2 from the left of the range. Column C shows the results displayed when the formula in Column B is used.
  4. This indicates to Excel how it should treat items where a match isn’t found :
    True (or non-zero) indicates it expects an ordered table and it will return the next item in the list after the point this item would have been. This is never used for simply finding items in a list. This would be used by accountants sometimes.
    False (or zero) will only find exact matches. Any item not found would return a #N/A value (See C4 below) which can be detected by using the ISNA() function.
Sep 20 '10 #7
I think I might have nearly got it! The formula I'm using is =VLOOKUP(D12,J5:K27,1)

D12 is the cell with the area of users to input their data.

J5:K27 are the two columns with corresponding answers

and the 1 is the first column that I want excel to look up and give me the answer from the 2nd column.

Could someone tell me whats wrong with the formula, as I keep getting the NA error!


Thanks

Em
Sep 21 '10 #8
I figured it out! Cheers for all your help

Em
Sep 21 '10 #9
NeoPa
32,556 Expert Mod 16PB
Hi Emma. Sorry for the lack of responses (See NeoPa Absence).

Your problem (as far as I can tell without the explanation and any data) is that you have a third parameter (1) which is probably wrong for both of the remaining parameter values. The first two parameters seem fine (but I would strongly recommend using the $ chars to fix the search range - as in VLOOKUP(D12,$J$5:$K$27,...)), but after that you need a third parameter (C from post #7) that should probably be 2. I'm assuming here you want to return the value from column K. After that you would need the value TRUE for the fourth parameter (D from post #7) to indicate not to require an exact match.

Good luck with your project :)
Sep 27 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: stefan.soderholm72 | last post by:
Hi, using VS2005 I want to be able to implement a ListView in details-mode with contextmenu-functionality like windows explorer. IE, I want to show a contextmenu when I right-click the...
3
by: MartinR | last post by:
Hi, I'm still new to writing code in vba as I've only been introduced to access three weeks ago. I have written this code below and it executes but does not do what I want it to do. What I want is...
29
AccessIdiot
by: AccessIdiot | last post by:
I'm sure this must be possible but I'm still a newbie and not sure how to do it. Part One: Using the good 'ol customers and orders tables and forms example - how would I go about putting a little...
1
by: wongray | last post by:
Hello, Is there a function in access that I can use to export my report into excel files automatically (like every day) without hitting any key or command? Thanks for your help in advance. ...
1
by: printline | last post by:
Hello all Hopefully someone can help me with this issue. I have some information from a database which i show in a table. In this table i have various columns that are filled out with some of...
5
by: Johnymap | last post by:
Hi everyone I have text file which looks like these: "index.txt" Johan 22 sebaya "home.hml" Mpho 23 leboa "index.frt" Tedesca 24 teba My problem is i want to read the number on the last...
2
by: Dave | last post by:
Access 2003 I have an unbound search form, which shows filtered search records in it’s sub-form. On the unbound search form I wish to place a button, which will close off the search form, and...
4
by: Pubs | last post by:
Hi all, I have application being written in C# where I have to calculate the text pixel height and width of the line being typed in rich text box. I need to get the pixel height of the character...
0
by: shaif | last post by:
Hello Friends, I am facing a problem to create PDF from excel to specific location by using Adobe PDF Printer ib VB. I used code: Dim xlbook As Excel.Workbook . . . . xlbook.PrintOut , ,...
2
by: pyrokat | last post by:
This is all i have right now and i cant figure out how to go further.. var numEntries; var max; var pt; ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.