Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
HI all
i have an excel worksheet and i need to search on this sheet passing 3 parameters. HOw can I do this using VBA? I used the Find method, but i can search using only 1 parameter and i need to use 2 or 3 parameters passed by form. Thanks to anyone that wants to help me. Nick |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Search (using Find) on the parameter that would be least likely to occur
(most unique). then for each one found, check the two other parameters. When all three are satisfied, then you are there. -- Regards, Tom Ogilvy "Nick" wrote in message om... HI all i have an excel worksheet and i need to search on this sheet passing 3 parameters. HOw can I do this using VBA? I used the Find method, but i can search using only 1 parameter and i need to use 2 or 3 parameters passed by form. Thanks to anyone that wants to help me. Nick |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() This macro below will allow you to add as many search criteria as yo like. It will select all values (either constants or formula values) tha match. You can modify the code to work with a form, with a next butto for instance, that would allow you to look at each cell that passed th criteria. The current example looks for values greater than a min value, les than a max value. Paste the below code into a module, then populat your excel sheet with random numbers and give it a try. Sub MS() Dim myrange As Object Dim myrange2 As Object Dim myFinishedRange As Object Dim rngConstants As Object, rngFormulas As Object Dim MinVal, MaxVal ' set your criteria here MinVal = 500 MaxVal = 1000 On Error Resume Next Set rngConstants = ActiveSheet.Cells.SpecialCells(xlConstants) Set rngFormulas = ActiveSheet.Cells.SpecialCells(xlFormulas) For Each cellz In rngConstants '/// put your search criteria here If (cellz.Value = MinVal And cellz.Value <= MaxVal) Then '/// If n = 0 Then Set myrange = cellz n = 1 Else Set myrange = Union(myrange, cellz) End If End If Next cellz myrange.Select On Error GoTo endit n = 0 For Each cellz In rngFormulas '// same criteria here If (cellz.Value = MinValue And cellz.Value <= MaxVal) Then '// If n = 0 Then Set myrange2 = cellz n = 1 Else Set myrange2 = Union(myrange2, cellz) End If End If Next cellz On Error Resume Next Set myFinishedRange = Union(myrange, myrange2) myFinishedRange.Select Exit Sub endit: Set myFinishedRange = myrange If myrange Is Nothing Then Exit Sub myFinishedRange.Select End Su -- crispb ----------------------------------------------------------------------- crispbd's Profile: http://www.excelforum.com/member.php...fo&userid=1088 View this thread: http://www.excelforum.com/showthread.php?threadid=27456 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You turn off your error handling too soon. If there are no formulas or no
constants, then you final union will error. Just some other things which might be considered with a looping approach. loops would be slow for large amounts of data. And considerations for using specialcells (although I like them as well). consideration of the 8192 problem with special cells. (Specialcells fails silently if there are more then 8192 separate areas). -- Regards, Tom Ogilvy "crispbd" wrote in message ... This macro below will allow you to add as many search criteria as you like. It will select all values (either constants or formula values) that match. You can modify the code to work with a form, with a next button for instance, that would allow you to look at each cell that passed the criteria. The current example looks for values greater than a min value, less than a max value. Paste the below code into a module, then populate your excel sheet with random numbers and give it a try. Sub MS() Dim myrange As Object Dim myrange2 As Object Dim myFinishedRange As Object Dim rngConstants As Object, rngFormulas As Object Dim MinVal, MaxVal ' set your criteria here MinVal = 500 MaxVal = 1000 On Error Resume Next Set rngConstants = ActiveSheet.Cells.SpecialCells(xlConstants) Set rngFormulas = ActiveSheet.Cells.SpecialCells(xlFormulas) For Each cellz In rngConstants '/// put your search criteria here If (cellz.Value = MinVal And cellz.Value <= MaxVal) Then '/// If n = 0 Then Set myrange = cellz n = 1 Else Set myrange = Union(myrange, cellz) End If End If Next cellz myrange.Select On Error GoTo endit n = 0 For Each cellz In rngFormulas '// same criteria here If (cellz.Value = MinValue And cellz.Value <= MaxVal) Then '// If n = 0 Then Set myrange2 = cellz n = 1 Else Set myrange2 = Union(myrange2, cellz) End If End If Next cellz On Error Resume Next Set myFinishedRange = Union(myrange, myrange2) myFinishedRange.Select Exit Sub endit: Set myFinishedRange = myrange If myrange Is Nothing Then Exit Sub myFinishedRange.Select End Sub -- crispbd ------------------------------------------------------------------------ crispbd's Profile: http://www.excelforum.com/member.php...o&userid=10880 View this thread: http://www.excelforum.com/showthread...hreadid=274567 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
?Passing argument/parameter | Excel Programming | |||
?Passing argument/parameter | Excel Programming | |||
Passing a parameter to Excel | Excel Programming | |||
Passing parameter from Excel to stored procedure? | Excel Programming |