J
Jim Berglund
I have been trying to run the following code, and am getting a Next without
For Error
Any Ideas?
Jim Berglund
Sub DelRows()
Dim i, n As Long
Dim wsNumFrum As Worksheet
Set wsNumFrum = Worksheets("Numbers from Reverse Directory")
n = wsNumFrum.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious).Row
For i = 1 To n
If Range(Cells(i, 1)).Value = "" Then
Range(Cells(i, 1), Cells(i, 5)).ClearContents
Else
Range(Cells(i, 1)).Select
If Left(Cells(i, 1), 5).Value = "Lname" Then
Range(Cells(i, 1), Cells(i, 5)).ClearContents
Else
If IsNumeric(Cells(i, 5).Value) Then
Range(Cells(i, 1), Cells(i, 5)).ClearContents
End If
Next
'Sort the data
ActiveWorkbook.Worksheets("Numbers from Reverse
Directory").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Numbers from Reverse
Directory").Sort.SortFields. _
Add Key:=Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Numbers from Reverse Directory").Sort
.SetRange Range("A1:E5001")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
For Error
Any Ideas?
Jim Berglund
Sub DelRows()
Dim i, n As Long
Dim wsNumFrum As Worksheet
Set wsNumFrum = Worksheets("Numbers from Reverse Directory")
n = wsNumFrum.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious).Row
For i = 1 To n
If Range(Cells(i, 1)).Value = "" Then
Range(Cells(i, 1), Cells(i, 5)).ClearContents
Else
Range(Cells(i, 1)).Select
If Left(Cells(i, 1), 5).Value = "Lname" Then
Range(Cells(i, 1), Cells(i, 5)).ClearContents
Else
If IsNumeric(Cells(i, 5).Value) Then
Range(Cells(i, 1), Cells(i, 5)).ClearContents
End If
Next
'Sort the data
ActiveWorkbook.Worksheets("Numbers from Reverse
Directory").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Numbers from Reverse
Directory").Sort.SortFields. _
Add Key:=Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Numbers from Reverse Directory").Sort
.SetRange Range("A1:E5001")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub