Identifying and separating groups of data.
Hi Matt,
Correcting, try:
Sub Test()
Dim arr As Variant
Dim i As Long
arr = Array("1241", "2365", "3585", "5843")
For i = LBound(arr) To UBound(arr)
Call FilterGroups(arr(i))
Next i
End Sub
---
Regards,
Norman
"Matt" wrote in message
ups.com...
Hi all,
Here we go again. Thanks to Toppers, I now have working code that is
starting to do what I want it to do. I've modified the code to the
following, changing the way it works a bit (I removed the code that
inserted spaces above and below the data, realizing it was doing more
harm than good for my purposes) and also formatting it so it was easier
for me to understand:
================================================== ======================
Option Explicit
Sub Test()
'Need code to loop through critical list.
Call FilterGroups("1234")
End Sub
Sub FilterGroups(SearchCode)
Dim LastRow As Long 'Last row of dataset
Dim SearchRange As Range 'Search range
Dim n As Long 'Current loop step
Dim c '
Dim FirstAddress As String '
Dim StoreRows() As Long '
Dim Check As Integer 'Check column
Dim i As Integer 'Incremental for retrieving stored rows
Dim r As Integer 'Current row
Dim bLevel As Integer 'Level of found code
LastRow = Cells(Rows.Count, "A").End(xlUp).Row 'Find and set last
row
Set SearchRange = Worksheets("Raw Data").Range("B2:B" & LastRow)
'Set search range
n = 0 'Set n variable to zero
'Search for all occurences of SearchCode and store row numbers
With SearchRange
Set c = .Find(SearchCode, LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
n = n + 1
ReDim Preserve StoreRows(n)
StoreRows(n) = c.Row
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < FirstAddress
End If
End With
If n = 0 Then 'Exit routine if search code was not found
MsgBox "Code " & SearchCode & " could not be found"
Exit Sub
End If
Check = 15 'Check column number
'For each occurence of "SearchCode" mark rows with "x" in "Check"
For i = 1 To n
r = StoreRows(i)
Cells(r, Check) = "x"
bLevel = Cells(r, 1) 'Store level of "SearchCode"
r = r + 1
Do While Cells(r, 1) bLevel 'Add "x" if level than level of
"SearchCode"
Cells(r, Check) = "x"
r = r + 1
Loop
Next
MsgBox "Search Complete"
End Sub
================================================== ======================
I now need to search from list of critical values, not just a single
value as in the code above ("1234"). Say I have a workbook titled
"critical_codes.xls" with a tab named "critical". The critical tab
looks something like this in column A. For aguments sake, say the
range is A1:A100:
Code
----
1241
2365
...
3585
5843
I can't seem to get the macro to reference this list to get the values
for SearchCode. The program isn't very happy with more than one value
for SearchCode. I'm sure this is very simple and I feel like a dunce
for even asking, but I'm at a loss.
Any help is greatly appreciated.
Best regards,
Matt
|