Hi
I'm very new to vba and am struggling with getting an if/then to loop throughout the worksheet. With the below code I'd like to find the next "yes" after the first one in the D column and then each and every "yes" in the D column throughout the active worksheet acting on each one. Then to end the sub after the final row. The individual if/elseif commands seem to work ok by themselves but I have made numerous attempts at the loop/findnext for it to run throughout without success
. I've now taken out my attempt at the loop. Can anyone have a look please and help me construct the loop? I expect there may be other errors as well.
Sub_CDA_v1()
Dim oRange As Range
Dim SearchString As String
Set oRange = ActiveSheet.Columns("D:D")
SearchString = "yes"
Set aCell = oRange.Find(What:=SearchString, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Set bCell = aCell.Offset(0, 1)
Set cCell = bCell.Offset(-1, 0)
Set dCell = bCell.Offset(0, 1)
Set eCell = cCell.Offset(0, 1)
Set fCell = bCell.Offset(0, 2)
Set gCell = cCell.Offset(0, 2)
Set hCell = fCell.Offset(0, 3)
Set iCell = gCell.Offset(0, 3)
Set jCell = aCell.Offset(-1, 0)
Set kCell = hCell.Offset(0, 1)
Set lCell = iCell.Offset(0, 1)
[/INDENT]If dCell = eCell And fCell = gCell And bCell = "Calls Forwarded" And cCell = "Voice Calls Terminating" Then
[/INDENT]bCell.Select
bCell.Select
Selection.Copy
cCell.Select
ActiveSheet.Paste
hCell.Select
Selection.Copy
iCell.Select
ActiveSheet.Paste
kCell.Select
Selection.Copy
lCell.Select
ActiveSheet.Paste
bCell.Select
Rows(ActiveCell.Row).EntireRow.Delete
ElseIf dCell = eCell And fCell = gCell And bCell = "Voice Calls Originating" And cCell = "Calls Forwarded" Then
cCell.Select
Selection.Copy
bCell.Select
ActiveSheet.Paste
iCell.Select
Selection.Copy
hCell.Select
ActiveSheet.Paste
lCell.Select
Selection.Copy
kCell.Select
ActiveSheet.Paste
jCell.Select
Selection.Copy
aCell.Select
ActiveSheet.Paste
cCell.Select
Rows(ActiveCell.Row).EntireRow.Delete
ElseIf dCell <> eCell Then
ElseIf fCell <> gCell Then
I'm very new to vba and am struggling with getting an if/then to loop throughout the worksheet. With the below code I'd like to find the next "yes" after the first one in the D column and then each and every "yes" in the D column throughout the active worksheet acting on each one. Then to end the sub after the final row. The individual if/elseif commands seem to work ok by themselves but I have made numerous attempts at the loop/findnext for it to run throughout without success
![Mad :mad: :mad:](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f621.png)
Sub_CDA_v1()
Dim oRange As Range
Dim SearchString As String
Set oRange = ActiveSheet.Columns("D:D")
SearchString = "yes"
Set aCell = oRange.Find(What:=SearchString, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Set bCell = aCell.Offset(0, 1)
Set cCell = bCell.Offset(-1, 0)
Set dCell = bCell.Offset(0, 1)
Set eCell = cCell.Offset(0, 1)
Set fCell = bCell.Offset(0, 2)
Set gCell = cCell.Offset(0, 2)
Set hCell = fCell.Offset(0, 3)
Set iCell = gCell.Offset(0, 3)
Set jCell = aCell.Offset(-1, 0)
Set kCell = hCell.Offset(0, 1)
Set lCell = iCell.Offset(0, 1)
[/INDENT]If dCell = eCell And fCell = gCell And bCell = "Calls Forwarded" And cCell = "Voice Calls Terminating" Then
[/INDENT]bCell.Select
Selection.Copy
hCell.Select
Selection.Copy
iCell.Select
ActiveSheet.Paste
kCell.Select
Selection.Copy
lCell.Select
ActiveSheet.Paste
bCell.Select
Rows(ActiveCell.Row).EntireRow.Delete
[/INDENT]cCell.Select
ActiveSheet.Paste
hCell.Select
Selection.Copy
iCell.Select
ActiveSheet.Paste
kCell.Select
Selection.Copy
lCell.Select
ActiveSheet.Paste
bCell.Select
Rows(ActiveCell.Row).EntireRow.Delete
ElseIf dCell = eCell And fCell = gCell And bCell = "Calls Forwarded" And cCell = "Voice Calls Originating" ThenbCell.Select
Selection.Copy
cCell.Select
ActiveSheet.Paste
hCell.Select
Selection.Copy
iCell.Select
ActiveSheet.Paste
kCell.Select
Selection.Copy
lCell.Select
ActiveSheet.Paste
bCell.Select
Rows(ActiveCell.Row).EntireRow.Delete
ElseIf dCell = eCell And fCell = gCell And bCell = "Voice Calls Originating" And cCell = "Calls Forwarded" Then
cCell.Select
Selection.Copy
bCell.Select
ActiveSheet.Paste
iCell.Select
Selection.Copy
hCell.Select
ActiveSheet.Paste
lCell.Select
Selection.Copy
kCell.Select
ActiveSheet.Paste
jCell.Select
Selection.Copy
aCell.Select
ActiveSheet.Paste
cCell.Select
Rows(ActiveCell.Row).EntireRow.Delete
ElseIf dCell <> eCell Then
ElseIf fCell <> gCell Then
End If
End Sub
End Sub