Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function lnArray(X() As Variant, Y() As Variant) As Variant
- Dim counter1 As Long
- Dim xcount As Long
- Dim t As Long
- Dim FinalResults() As Variant
- counter1 = 0
- For xcount = LBound(X) To UBound(X)
- On Error Resume Next
- t = Application.Match(X(xcount, 1), Y, 0)
- If Err.Number = 0 Then
- If (t > 0) Then
- counter1 = counter1 + 1
- ReDim Preserve FinalResults(counter1)
- FinalResults(counter1) = X(xcount, 1)
- End If
- End If
- On Error GoTo 0
- Next xcount
- lnArray = FinalResults
- End Function
- Sub search()
- Dim Results1() As Variant, Results2() As Variant, FinalResults() As Variant
- FinalResults = lnArray(Results1, Results2)
- End Sub
- Function lnArray(ByRef X() As Variant, ByRef Y() As Variant) As Variant
- Dim counter1 As Long
- Dim xcount As Long
- Dim t As Long
- Dim FinalResults() As Variant
- counter1 = 0
- For xcount = LBound(X) To UBound(X)
- On Error Resume Next
- t = 0
- t = Application.Match(X(xcount), Y, 0)
- If Err.Number = 0 Then
- If (t > 0) Then
- counter1 = counter1 + 1
- ReDim Preserve FinalResults(counter1)
- FinalResults(counter1) = X(xcount)
- End If
- End If
- On Error GoTo 0
- Next xcount
- lnArray = FinalResults
- End Function
- Sub Search()
- Dim TextBox1 As Long
- Dim TextBox3 As Long
- Dim Results1() As Variant
- Dim Results2() As Variant
- Dim FindRange1 As Range
- Dim Find1 As Range
- Dim FindRange2 As Range
- Dim Find2 As Range
- Dim i1 As Long
- Dim i2 As Long
- TextBox1 = ILsearch.TextBox1.Value
- TextBox3 = ILsearch.TextBox3.Value
- Set FindRange1 = Worksheets("Properties").Range("P7:P1000")
- If ILsearch.P1B1.Value = True Then
- For Each Find1 In FindRange1
- If (Find1.Value < TextBox1) And (Find1.Value > 0) Then
- i1 = i1 + 1
- ReDim Preserve Results1(i1)
- Results1(i1) = Find1.Address
- End If
- Next Find1
- End If
- Set FindRange2 = Worksheets("Properties").Range("P7:P1000")
- If ILsearch.P2B1.Value = True Then
- For Each Find2 In FindRange2
- If (Find2.Value < TextBox3) And (Find2.Value > 0) Then
- i2 = i2 + 1
- ReDim Preserve Results2(i2)
- Results2(i2) = Find2.Address
- End If
- Next Find2
- End If
- End Sub
- 'For a single property selection
- Dim p1results As Range
- Dim shProperties As Worksheet
- Dim shSearchResult As Worksheet
- Set shProperties = ActiveWorkbook.Worksheets("properties")
- Set shSearchResult = ActiveWorkbook.Worksheets("searchresult")
- If (ILsearch.ComboBox1.Enabled = True) And (ILsearch.ComboBox2.Enabled = False) And (ILsearch.ComboBox3.Enabled = False) Then
- On Error Resume Next
- For i1 = LBound(Results1) To UBound(Results1)
- Set NextRow = shSearchResult.Cells(shSearchResult.Rows.Count, 4).End(xlUp).Offset(1, -3)
- shProperties.Range(Results1(i1)).EntireRow.Copy NextRow
- Next i1
- End If
- 'repeat same if/then code for Results2 and Results3
- Dim FinalResults() As Variant
- Dim FinCount As Integer
- Dim Counter1 As Long
- Dim t As Long
- If (ILsearch.ComboBox1.Enabled = True) And (ILsearch.ComboBox2.Enabled = True) And (ILsearch.ComboBox2.Enabled = False) Then
- If IsArrayAllocated(Results1) = True And IsArrayAllocated(Results2) = True Then
- Else
- Debug.Print "Empty Array"
- End If
- FinalResults = lnArray(Results1, Results2)
- On Error Resume Next
- For FinCount = LBound(FinalResults) To UBound(FinalResults)
- Set NextRow = shSearchResult.Cells(shSearchResult.Rows.Count, 4).End(xlUp).Offset(1, -3)
- shProperties.Range(Results3(i3)).EntireRow.Copy NextRow
- Next FinCount
- End If
- 'repeat same if/then for (1+3) arrangement and (2+3)arrangement
- Dim intResults() As Variant
- If (ILsearch.ComboBox1.Enabled = True) And (ILsearch.ComboBox2.Enabled = True) And (ILsearch.ComboBox2.Enabled = True) Then
- intResults = lnArray(Results1, Results2)
- FinalResults = lnArray(intResults, Results3)
- On Error Resume Next
- For FinCount = LBound(FinalResults) To UBound(FinalResults)
- Set NextRow = shSearchResult.Cells(shSearchResult.Rows.Count, 4).End(xlUp).Offset(1, -3)
- shProperties.Range(Results3(i3)).EntireRow.Copy NextRow
- Next FinCount
- End If
- t = Application.Match(X(xcount, 1), Y, 0)
- If IsEmpty(t) Then
- counter1 = counter1 + 1
- End If
- Sub Search()
- Dim TextBox1 As Long
- Dim TextBox3 As Long
- Dim Results1() As Variant
- Dim Results2() As Variant
- Dim FindRange1 As Range
- Dim Find1 As Range
- Dim FindRange2 As Range
- Dim Find2 As Range
- Dim i1 As Long
- Dim i2 As Long
- TextBox1 = ILsearch.TextBox1.Value
- TextBox3 = ILsearch.TextBox3.Value
- Set FindRange1 = Worksheets("Properties").Range("P7:P1000")
- If ILsearch.P1B1.Value = True Then
- For Each Find1 In FindRange1
- If (Find1.Value < TextBox1) And (Find1.Value > 0) Then
- i1 = i1 + 1
- ReDim Preserve Results1(i1)
- Results1(i1) = Find1.Address
- End If
- Next Find1
- End If
- Set FindRange2 = Worksheets("Properties").Range("P7:P1000")
- If ILsearch.P2B1.Value = True Then
- For Each Find2 In FindRange2
- If (Find2.Value < TextBox3) And (Find2.Value > 0) Then
- i2 = i2 + 1
- ReDim Preserve Results2(i2)
- Results2(i2) = Find2.Address
- End If
- Next Find2
- End If
- If IsArrayAllocated(Results1) = True And _
- IsArrayAllocated(Results2) = True Then
- Z = lnArray(Results1, Results2)
- Else
- Debug.Print "Empty Array"
- End If
- End Sub
- Function lnArray(X() As Variant, Y() As Variant) As Variant
- Dim counter1 As Long
- Dim xcount As Long
- Dim t As Long
- Dim FinalResults() As Variant
- counter1 = 0
- For xcount = LBound(X) To UBound(X)
- On Error Resume Next
- t = 0
- t = Application.Match(X(xcount), Y, 0)
- If (t > 0) Then
- counter1 = counter1 + 1
- ReDim Preserve FinalResults(counter1)
- FinalResults(counter1) = X(xcount)
- End If
- On Error GoTo 0
- Next xcount
- lnArray = FinalResults
- End Function
- Function IsArrayAllocated(Arr As Variant) As Boolean
- '**Determines whether an array is allocated to avoid UBound errors
- On Error Resume Next
- IsArrayAllocated = IsArray(Arr) And _
- Not IsError(LBound(Arr, 1)) And _
- LBound(Arr, 1) <= UBound(Arr, 1)
- On Error GoTo 0
- End Function
- For xcount = LBound(X) To UBound(X)
- On Error Resume Next
- t = 0
- t = Application.Match(X(xcount), Y, 0)
- If Err.Number = 0 Then
- If (t > 0) Then
- For xcount = LBound(X) To UBound(X)
- On Error Resume Next
- t = 0
- t = Application.Match(X(xcount), Y, 0)
- If Err.Number <> 0 Then
- Err.clear 'ignore match error
- Else
- If (t > 0) Then
- debug.print Err.number,Err.message....
Add Comment
Please, Sign In to add comment