C
Carrie_Loos via OfficeKB.com
Can anyone tell me how to write the string of code to stop a macro at a
certain point? I have the following macro that runs through a range but
because I need to use the cell.find and activate mode when it loops around it
ignores the range and continues on, I am thinking if I could just stop it at
the bottom of column AU where I have a "999" then it would solve my problems.
Sub FindOnes()
Dim r As Range
Dim Topcell As Variant
Dim Bottomcell As Variant
Set r = ActiveSheet.Range("E3:AU65535")
For Each c In r
Cells.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:
= _
False, SearchFormat:=True).Activate
If ActiveCell.Value = 1 Then
Set Topcell = ActiveCell
Cells.Find(What:="2", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:
= _
False, SearchFormat:=True).Activate
If ActiveCell.Value = 2 Then
Set Bottomcell = ActiveCell
If Topcell = 1 Then Set Topcell = Topcell
Range(Topcell, Bottomcell).Select
Selection.FillDown
Bottomcell.Select
End If
End If
???????Stop at the end of column AU???????
Next
End Sub
certain point? I have the following macro that runs through a range but
because I need to use the cell.find and activate mode when it loops around it
ignores the range and continues on, I am thinking if I could just stop it at
the bottom of column AU where I have a "999" then it would solve my problems.
Sub FindOnes()
Dim r As Range
Dim Topcell As Variant
Dim Bottomcell As Variant
Set r = ActiveSheet.Range("E3:AU65535")
For Each c In r
Cells.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:
= _
False, SearchFormat:=True).Activate
If ActiveCell.Value = 1 Then
Set Topcell = ActiveCell
Cells.Find(What:="2", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:
= _
False, SearchFormat:=True).Activate
If ActiveCell.Value = 2 Then
Set Bottomcell = ActiveCell
If Topcell = 1 Then Set Topcell = Topcell
Range(Topcell, Bottomcell).Select
Selection.FillDown
Bottomcell.Select
End If
End If
???????Stop at the end of column AU???????
Next
End Sub