searching a table

A

aya

Hi,
How can I search a table in more than one column?
for example
if I have columns:
voltage temp value
and I need to find a value according to a certain voltage and a certain
temp?
(there might be more than one temp per voltage)

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
?

???

aya:

You can try this command form the menu

"DATA"==>"Advanced Filter"

--

???@??

*??????**??????*



| Hi,
| How can I search a table in more than one column?
| for example
| if I have columns:
| voltage temp value
| and I need to find a value according to a certain voltage and a certain
| temp?
| (there might be more than one temp per voltage)
|
| ** Posted via: http://www.ozgrid.com
| Excel Templates, Training, Add-ins & Business Software Galore!
| Free Excel Forum http://www.ozgrid.com/forum ***
 
A

aya

I need the search to be a part of a function, I have a variable who
should have the value of the cell. I cant use the filter option because
I will receive as input to the function which temp and voltage is needed
so I won't know this in advance.
is there any way to use something like VLOOKUP to find the appropriate
value and insert it into a variable?

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
D

Dave Hawley

Hi

You would need VBA for this. See code below.

Sub DualFind()
Dim vFind1 As String, vFind2 As String
Dim rFound As Range, lLoop As Long
Dim bFound As Boolean
Dim rLookIn1 As Range, rLookIn2 As Range

If Selection.Columns.Count <> 2 And Selection.Areas.Count = 1 Then
MsgBox "Must select 2 columns to search", vbOKOnly, "ozgrid.com"
Exit Sub
ElseIf Selection.Areas.Count = 1 Then
MsgBox "Must select 2 columns to search", vbOKOnly, "ozgrid.com"
Exit Sub
End If

vFind1 = InputBox("Find What: First value?", "FIND FIRST VALUE")
If vFind1 = vbNullString Then Exit Sub

vFind2 = InputBox("Find What: Second value?", "FIND SECOND VALUE")
If vFind2 = vbNullString Then Exit Sub

If Selection.Areas.Count > 1 Then
Set rLookIn1 = Selection.Areas(1).Columns(1)
Set rLookIn2 = Selection.Areas(2).Columns(1)
Else
Set rLookIn1 = Selection.Columns(1)
Set rLookIn2 = Selection.Columns(2)
End If

Set rFound = rLookIn1.Cells(1, 1)
For lLoop = 1 To WorksheetFunction.CountIf(rLookIn1, vFind1)
Set rFound = rLookIn1.Find(What:=vFind1, _
After:=rFound, LookAt:=xlWhole)
If UCase(rLookIn2.Cells(rFound.Row, 1)) = UCase(vFind2) Then
bFound = True
Exit For
End If
Next lLoop

If bFound = True Then
MsgBox "Match found", vbInformation, "ozgrid.com"
Range(rFound, rLookIn2.Cells(rFound.Row, 1)).Select
Else
MsgBox "Sorry, no match found", vbInformation, "ozgrid.com"
End If
End Sub


To use the code, push Alt+F11 and go to Insert>Module. Now paste in the
code below. Click the top right X to get back to Excel and Save.

Now assign the macro to a control button, textbox etc or push Alt+F8 and
click the macro "DualFind" the "Run"

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
F

Frank Kabel

Hi
try the following array formula (entered with CTRL+SHIFT+ENTER):
=INDEX(C1:C100,MATCH(1,(A1:A100=E1)*(B1:B100=F1),0))

where E1 stores the voltage and F1 the temp to search
 
F

Frank Kabel

Hi Dave
if I understood the OP correctly no VBA needed :)
(Though I like your approach)
 
A

aya

thank you so much!!!
could you please tell me how to alter this macro into a function?
i need to have:
function func(volt,temp)
where volt is the value i want to find in the fist column and temp is
the value i need to find in the second column (instead of VFind1 and
VFind2 in your macro)
thanks

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
D

Dave Hawley

Unfortunately Find cannot be used in Functions.

If you have to use a Function you should either use Franks. Or, use
Franks Worksheet Function in VBA to create a Custom Function.

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
D

David McRitchie

Hi "aya" <[email protected]> ,
A function can only return a value, possibly the part you are
having a problem with is that you must return the value by
using the function name in your assignment. i.e.

Function CharW(dec As Long) As String
CharW = ChrW(dec)
End Function

The other part is that in using it, if it is not in the same workbook
you probably have to specify the workbookname
=CharW(8540)
=personal.xls!CharW(8540)

The more specific you can ask a question possibly with some sample
code (as text), the more likely you are to get a fast, accurate answer.
Rather than make people guess as to what your problem is and then
also try to solve it..
 
F

Frank Kabel

Hi
do you really need a VBA solution?. Why not use the worksheet function
directly in a cell?
 
A

aya

ok, I'll be more specific...

lets say we have the table:

volt temp value
1 2 20
1 3 21
1 4 22
2 5 23
2 6 24
2 7 25
3 8 26
3 9 27
3 10 28

when entering volt=2 and temp=6 as parameters to the function, I want
the function to search the table and return 24 as a result, since thats
the value for the specified voltage and temprature
sorry for being a nag...its a little hard for me to explain this...
hope this makes it clearer!

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
F

Frank Kabel

Hi
and where do you want the result to be displayed and where do you put
the search values.
 
A

aya

well, the search values are not always in the same place:

Function func(volt,temp)
search for the result as explained abov
in the table
func=result
end function

meaning the result is going to be in the cell from which we activated
the function and the search values are in one sheet - when activating
the function the user enters which temp and volt he wants

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
F

Frank Kabel

Hi
then no need for a user defined function. Say you have the values on
your sheet in the following cells:
E1: value for volt to search
F1: value for temp to seachr
and column A:C store your table then use the following array formula
(entered with CTRL+SHIFT+ENTER) in cell G1:
=INDEX(C1:C100,MATCH(1,(A1:A100=E1)*(B1:B100=F1),0))

No need for VBA in this case. The user simply changes cell E1 and F1
and cell G1 will automatically show the associated value
 
R

Ragdyer

Is there a reason I'm unaware of, that no one has suggested a simple
Sumproduct formula, which doesn't have to be array entered, as a possible
solution?

Volts in col A - A3:A100
Temp in col B - B3:B100
Value in col C - C3:C100

Labels in A1 - B1 - C1

User input of search values,
Volts in A2
Temp in B2

Enter this formula in C2:

=SUMPRODUCT((A3:A100=A2)*(B3:B100=B2)*C3:C100)
 
F

Frank Kabel

Hi
yes this would work if the value columns contains only numbers (as in
the example the OP provided). Won't work, if the value column could
also contain text values
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top