Guest User

Untitled

a guest
Jul 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. Function lnArray(X() As Variant, Y() As Variant) As Variant
  2. Dim counter1 As Long
  3. Dim xcount As Long
  4. Dim t As Long
  5. Dim FinalResults() As Variant
  6.  
  7. counter1 = 0
  8. For xcount = LBound(X) To UBound(X)
  9. On Error Resume Next
  10. t = Application.Match(X(xcount, 1), Y, 0)
  11. If Err.Number = 0 Then
  12. If (t > 0) Then
  13. counter1 = counter1 + 1
  14. ReDim Preserve FinalResults(counter1)
  15. FinalResults(counter1) = X(xcount, 1)
  16. End If
  17. End If
  18. On Error GoTo 0
  19. Next xcount
  20.  
  21. lnArray = FinalResults
  22. End Function
  23.  
  24. Sub search()
  25. Dim Results1() As Variant, Results2() As Variant, FinalResults() As Variant
  26.  
  27. FinalResults = lnArray(Results1, Results2)
  28. End Sub
  29.  
  30. Function lnArray(ByRef X() As Variant, ByRef Y() As Variant) As Variant
  31. Dim counter1 As Long
  32. Dim xcount As Long
  33. Dim t As Long
  34. Dim FinalResults() As Variant
  35.  
  36. counter1 = 0
  37. For xcount = LBound(X) To UBound(X)
  38. On Error Resume Next
  39. t = 0
  40. t = Application.Match(X(xcount), Y, 0)
  41. If Err.Number = 0 Then
  42. If (t > 0) Then
  43. counter1 = counter1 + 1
  44. ReDim Preserve FinalResults(counter1)
  45. FinalResults(counter1) = X(xcount)
  46. End If
  47. End If
  48. On Error GoTo 0
  49. Next xcount
  50.  
  51. lnArray = FinalResults
  52. End Function
  53.  
  54. Sub Search()
  55.  
  56. Dim TextBox1 As Long
  57. Dim TextBox3 As Long
  58. Dim Results1() As Variant
  59. Dim Results2() As Variant
  60. Dim FindRange1 As Range
  61. Dim Find1 As Range
  62. Dim FindRange2 As Range
  63. Dim Find2 As Range
  64. Dim i1 As Long
  65. Dim i2 As Long
  66.  
  67. TextBox1 = ILsearch.TextBox1.Value
  68. TextBox3 = ILsearch.TextBox3.Value
  69.  
  70. Set FindRange1 = Worksheets("Properties").Range("P7:P1000")
  71. If ILsearch.P1B1.Value = True Then
  72. For Each Find1 In FindRange1
  73. If (Find1.Value < TextBox1) And (Find1.Value > 0) Then
  74. i1 = i1 + 1
  75. ReDim Preserve Results1(i1)
  76. Results1(i1) = Find1.Address
  77. End If
  78. Next Find1
  79. End If
  80.  
  81. Set FindRange2 = Worksheets("Properties").Range("P7:P1000")
  82. If ILsearch.P2B1.Value = True Then
  83. For Each Find2 In FindRange2
  84. If (Find2.Value < TextBox3) And (Find2.Value > 0) Then
  85. i2 = i2 + 1
  86. ReDim Preserve Results2(i2)
  87. Results2(i2) = Find2.Address
  88. End If
  89. Next Find2
  90. End If
  91. End Sub
  92.  
  93. 'For a single property selection
  94. Dim p1results As Range
  95. Dim shProperties As Worksheet
  96. Dim shSearchResult As Worksheet
  97.  
  98. Set shProperties = ActiveWorkbook.Worksheets("properties")
  99. Set shSearchResult = ActiveWorkbook.Worksheets("searchresult")
  100.  
  101. If (ILsearch.ComboBox1.Enabled = True) And (ILsearch.ComboBox2.Enabled = False) And (ILsearch.ComboBox3.Enabled = False) Then
  102. On Error Resume Next
  103. For i1 = LBound(Results1) To UBound(Results1)
  104. Set NextRow = shSearchResult.Cells(shSearchResult.Rows.Count, 4).End(xlUp).Offset(1, -3)
  105. shProperties.Range(Results1(i1)).EntireRow.Copy NextRow
  106. Next i1
  107. End If
  108.  
  109. 'repeat same if/then code for Results2 and Results3
  110.  
  111. Dim FinalResults() As Variant
  112. Dim FinCount As Integer
  113. Dim Counter1 As Long
  114. Dim t As Long
  115.  
  116. If (ILsearch.ComboBox1.Enabled = True) And (ILsearch.ComboBox2.Enabled = True) And (ILsearch.ComboBox2.Enabled = False) Then
  117. If IsArrayAllocated(Results1) = True And IsArrayAllocated(Results2) = True Then
  118. Else
  119. Debug.Print "Empty Array"
  120. End If
  121.  
  122. FinalResults = lnArray(Results1, Results2)
  123. On Error Resume Next
  124. For FinCount = LBound(FinalResults) To UBound(FinalResults)
  125. Set NextRow = shSearchResult.Cells(shSearchResult.Rows.Count, 4).End(xlUp).Offset(1, -3)
  126. shProperties.Range(Results3(i3)).EntireRow.Copy NextRow
  127. Next FinCount
  128. End If
  129. 'repeat same if/then for (1+3) arrangement and (2+3)arrangement
  130.  
  131. Dim intResults() As Variant
  132.  
  133. If (ILsearch.ComboBox1.Enabled = True) And (ILsearch.ComboBox2.Enabled = True) And (ILsearch.ComboBox2.Enabled = True) Then
  134. intResults = lnArray(Results1, Results2)
  135. FinalResults = lnArray(intResults, Results3)
  136. On Error Resume Next
  137. For FinCount = LBound(FinalResults) To UBound(FinalResults)
  138. Set NextRow = shSearchResult.Cells(shSearchResult.Rows.Count, 4).End(xlUp).Offset(1, -3)
  139. shProperties.Range(Results3(i3)).EntireRow.Copy NextRow
  140. Next FinCount
  141. End If
  142.  
  143. t = Application.Match(X(xcount, 1), Y, 0)
  144. If IsEmpty(t) Then
  145. counter1 = counter1 + 1
  146. End If
  147.  
  148. Sub Search()
  149.  
  150. Dim TextBox1 As Long
  151. Dim TextBox3 As Long
  152. Dim Results1() As Variant
  153. Dim Results2() As Variant
  154. Dim FindRange1 As Range
  155. Dim Find1 As Range
  156. Dim FindRange2 As Range
  157. Dim Find2 As Range
  158. Dim i1 As Long
  159. Dim i2 As Long
  160.  
  161. TextBox1 = ILsearch.TextBox1.Value
  162. TextBox3 = ILsearch.TextBox3.Value
  163.  
  164. Set FindRange1 = Worksheets("Properties").Range("P7:P1000")
  165. If ILsearch.P1B1.Value = True Then
  166. For Each Find1 In FindRange1
  167. If (Find1.Value < TextBox1) And (Find1.Value > 0) Then
  168. i1 = i1 + 1
  169. ReDim Preserve Results1(i1)
  170. Results1(i1) = Find1.Address
  171. End If
  172. Next Find1
  173. End If
  174.  
  175. Set FindRange2 = Worksheets("Properties").Range("P7:P1000")
  176. If ILsearch.P2B1.Value = True Then
  177. For Each Find2 In FindRange2
  178. If (Find2.Value < TextBox3) And (Find2.Value > 0) Then
  179. i2 = i2 + 1
  180. ReDim Preserve Results2(i2)
  181. Results2(i2) = Find2.Address
  182. End If
  183. Next Find2
  184. End If
  185. If IsArrayAllocated(Results1) = True And _
  186. IsArrayAllocated(Results2) = True Then
  187. Z = lnArray(Results1, Results2)
  188. Else
  189. Debug.Print "Empty Array"
  190. End If
  191. End Sub
  192.  
  193.  
  194. Function lnArray(X() As Variant, Y() As Variant) As Variant
  195. Dim counter1 As Long
  196. Dim xcount As Long
  197. Dim t As Long
  198. Dim FinalResults() As Variant
  199.  
  200. counter1 = 0
  201. For xcount = LBound(X) To UBound(X)
  202. On Error Resume Next
  203. t = 0
  204. t = Application.Match(X(xcount), Y, 0)
  205. If (t > 0) Then
  206. counter1 = counter1 + 1
  207. ReDim Preserve FinalResults(counter1)
  208. FinalResults(counter1) = X(xcount)
  209. End If
  210. On Error GoTo 0
  211. Next xcount
  212.  
  213. lnArray = FinalResults
  214. End Function
  215.  
  216. Function IsArrayAllocated(Arr As Variant) As Boolean
  217. '**Determines whether an array is allocated to avoid UBound errors
  218. On Error Resume Next
  219. IsArrayAllocated = IsArray(Arr) And _
  220. Not IsError(LBound(Arr, 1)) And _
  221. LBound(Arr, 1) <= UBound(Arr, 1)
  222. On Error GoTo 0
  223. End Function
  224.  
  225. For xcount = LBound(X) To UBound(X)
  226. On Error Resume Next
  227. t = 0
  228. t = Application.Match(X(xcount), Y, 0)
  229. If Err.Number = 0 Then
  230. If (t > 0) Then
  231.  
  232. For xcount = LBound(X) To UBound(X)
  233. On Error Resume Next
  234. t = 0
  235. t = Application.Match(X(xcount), Y, 0)
  236. If Err.Number <> 0 Then
  237. Err.clear 'ignore match error
  238. Else
  239. If (t > 0) Then
  240.  
  241. debug.print Err.number,Err.message....
Add Comment
Please, Sign In to add comment