Giri
07-09-2011, 02:23 AM
Hi Guys,
With the following code, I can't seem to get out of the two loops below which I have made comments next to.
Therefore the macro doesn't go onto the next loop. I want the two loops to end when it encounters a blank cell. Everything else, seems to be working alright.
If anyone can help with this, I'd greatly appreciate it!!
Thank you!
Giri
Option Explicit
Public Sub AmpLife()
Dim c As Range
Dim n As Integer
Dim x As Integer
Dim row As Integer
Dim stringArray(3) As String
Dim searchString As String
'Application.ScreenUpdating = False
row = Range("D2").End(xlDown).row
n = 0
For Each c In Range("D2:D" & row)
For x = 0 To 2
searchString = c.Value
stringArray(x) = Split(searchString, " ")(n)
n = n + 1
Next x
c.Select
On Error Resume Next
If stringArray(0) <> "AMP" Or stringArray(1) <> "Life" Or stringArray(2) <> "Ltd" Then
c.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
stringArray(1) = Split(ActiveCell.Value, " ")(1)
stringArray(2) = Split(ActiveCell.Value, " ")(2)
Do While stringArray(0) <> "AMP" Or stringArray(1) _ 'THIS LOOP
<> "Life" Or stringArray(2) <> "Ltd" And IsEmpty(ActiveCell) = False
c.Select
ActiveCell.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
stringArray(1) = Split(ActiveCell.Value, " ")(1)
stringArray(2) = Split(ActiveCell.Value, " ")(2)
Loop
End If
n = 0
Next c
On Error GoTo 0
row = Range("E2").End(xlDown).row
For Each c In Range("E2:E" & row)
c.Select
stringArray(0) = Split(ActiveCell.Value, " ")(0)
If stringArray(0) <> "Internal" Then
c.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
End If
Do While stringArray(0) <> "Internal" 'THIS LOOP
ActiveCell.Select
ActiveCell.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
Loop
Next c
'Application.ScreenUpdating = True
End Sub
With the following code, I can't seem to get out of the two loops below which I have made comments next to.
Therefore the macro doesn't go onto the next loop. I want the two loops to end when it encounters a blank cell. Everything else, seems to be working alright.
If anyone can help with this, I'd greatly appreciate it!!
Thank you!
Giri
Option Explicit
Public Sub AmpLife()
Dim c As Range
Dim n As Integer
Dim x As Integer
Dim row As Integer
Dim stringArray(3) As String
Dim searchString As String
'Application.ScreenUpdating = False
row = Range("D2").End(xlDown).row
n = 0
For Each c In Range("D2:D" & row)
For x = 0 To 2
searchString = c.Value
stringArray(x) = Split(searchString, " ")(n)
n = n + 1
Next x
c.Select
On Error Resume Next
If stringArray(0) <> "AMP" Or stringArray(1) <> "Life" Or stringArray(2) <> "Ltd" Then
c.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
stringArray(1) = Split(ActiveCell.Value, " ")(1)
stringArray(2) = Split(ActiveCell.Value, " ")(2)
Do While stringArray(0) <> "AMP" Or stringArray(1) _ 'THIS LOOP
<> "Life" Or stringArray(2) <> "Ltd" And IsEmpty(ActiveCell) = False
c.Select
ActiveCell.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
stringArray(1) = Split(ActiveCell.Value, " ")(1)
stringArray(2) = Split(ActiveCell.Value, " ")(2)
Loop
End If
n = 0
Next c
On Error GoTo 0
row = Range("E2").End(xlDown).row
For Each c In Range("E2:E" & row)
c.Select
stringArray(0) = Split(ActiveCell.Value, " ")(0)
If stringArray(0) <> "Internal" Then
c.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
End If
Do While stringArray(0) <> "Internal" 'THIS LOOP
ActiveCell.Select
ActiveCell.EntireRow.Delete
stringArray(0) = Split(ActiveCell.Value, " ")(0)
Loop
Next c
'Application.ScreenUpdating = True
End Sub