I have nested a For / Next searching for value = 1. My question is How do I use the For / Next to search column 2 for values of 1 UNTIL the value in Column 2 = 0?
The value of 1 may be listed 1 or more times in between a values of 0 in column 2. The design should list only the 1's that sequentially follow a value 0 until the next value of 0 is identified in column 2.
Example of my code:
Sub FindAll(strECNN)
Dim rStartCell As Range
Dim i As Integer, j As Integer
Dim f As Worksheet, t As Worksheet
Dim b As Long
b = 10
Workbooks(strECNN & "_BOM.xls").Worksheets(strECNN & "_BOM").Activate
Set f = ActiveSheet
Workbooks("ECN Navigator Pro.xls").Worksheets("Alternates-Substitutions").Activate
Set t = ActiveSheet
Set rStartCell = f.Range("B1")
For i = 1 To WorksheetFunction.CountIf(f.Columns(2), "0")
Set rStartCell = f.Columns(2).Find(What:="0", After:=rStartCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If rStartCell <> "" And rStartCell.Offset(0, 12) = rStartCell.Offset(0, 1) Then
t.Range("G" & b) = rStartCell.Offset(0, 0)
t.Range("H" & b) = rStartCell.Offset(0, 8)
t.Range("J" & b) = rStartCell.Offset(0, 1)
t.Range("R" & b) = rStartCell.Offset(0, 2)
t.Range("T" & b) = rStartCell.Offset(0, 3)
t.Range("U" & b) = rStartCell.Offset(0, 4)
t.Range("W" & b) = rStartCell.Offset(0, 5)
t.Range("X" & b) = rStartCell.Offset(0, 6)
b = b + 1
End If
MsgBox "0 found in " & rStartCell.Address
'''Nested For Next to identify value = 1 in column 2
For j = 1 To WorksheetFunction.CountIf(f.Columns(2), "1")
Set rStartCell = f.Columns(2).Find(What:="1", After:=rStartCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If rStartCell <> "" And rStartCell.Offset(0, 12) = rStartCell.Offset(0, 1) Then
t.Range("G" & b) = rStartCell.Offset(0, 0)
t.Range("H" & b) = rStartCell.Offset(0, 8)
t.Range("J" & b) = rStartCell.Offset(0, 1)
t.Range("R" & b) = rStartCell.Offset(0, 2)
t.Range("T" & b) = rStartCell.Offset(0, 3)
t.Range("U" & b) = rStartCell.Offset(0, 4)
t.Range("W" & b) = rStartCell.Offset(0, 5)
t.Range("X" & b) = rStartCell.Offset(0, 6)
b = b + 1
End If
MsgBox "1 found in " & rStartCell.Address
Next j
Next i
End Sub
Thanks so much for the HELP,
John
The value of 1 may be listed 1 or more times in between a values of 0 in column 2. The design should list only the 1's that sequentially follow a value 0 until the next value of 0 is identified in column 2.
Example of my code:
Sub FindAll(strECNN)
Dim rStartCell As Range
Dim i As Integer, j As Integer
Dim f As Worksheet, t As Worksheet
Dim b As Long
b = 10
Workbooks(strECNN & "_BOM.xls").Worksheets(strECNN & "_BOM").Activate
Set f = ActiveSheet
Workbooks("ECN Navigator Pro.xls").Worksheets("Alternates-Substitutions").Activate
Set t = ActiveSheet
Set rStartCell = f.Range("B1")
For i = 1 To WorksheetFunction.CountIf(f.Columns(2), "0")
Set rStartCell = f.Columns(2).Find(What:="0", After:=rStartCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If rStartCell <> "" And rStartCell.Offset(0, 12) = rStartCell.Offset(0, 1) Then
t.Range("G" & b) = rStartCell.Offset(0, 0)
t.Range("H" & b) = rStartCell.Offset(0, 8)
t.Range("J" & b) = rStartCell.Offset(0, 1)
t.Range("R" & b) = rStartCell.Offset(0, 2)
t.Range("T" & b) = rStartCell.Offset(0, 3)
t.Range("U" & b) = rStartCell.Offset(0, 4)
t.Range("W" & b) = rStartCell.Offset(0, 5)
t.Range("X" & b) = rStartCell.Offset(0, 6)
b = b + 1
End If
MsgBox "0 found in " & rStartCell.Address
'''Nested For Next to identify value = 1 in column 2
For j = 1 To WorksheetFunction.CountIf(f.Columns(2), "1")
Set rStartCell = f.Columns(2).Find(What:="1", After:=rStartCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If rStartCell <> "" And rStartCell.Offset(0, 12) = rStartCell.Offset(0, 1) Then
t.Range("G" & b) = rStartCell.Offset(0, 0)
t.Range("H" & b) = rStartCell.Offset(0, 8)
t.Range("J" & b) = rStartCell.Offset(0, 1)
t.Range("R" & b) = rStartCell.Offset(0, 2)
t.Range("T" & b) = rStartCell.Offset(0, 3)
t.Range("U" & b) = rStartCell.Offset(0, 4)
t.Range("W" & b) = rStartCell.Offset(0, 5)
t.Range("X" & b) = rStartCell.Offset(0, 6)
b = b + 1
End If
MsgBox "1 found in " & rStartCell.Address
Next j
Next i
End Sub
Thanks so much for the HELP,
John