استاذ مختار
اكتب هذا الكود في الصفحة المعنية
يجب تصحيح غلطة في هذا السطر (Set movrange = Cells(i + 1, 2
لتصبح (Set movrange = Cells(i , 2
Sub remove_and_sorte()
Dim ws As Worksheet
Dim myrange As Range
Dim movrange As Range
Dim lr As Integer
Dim lr1 As Integer
'''''''''''''''''''''''''''''
Set ws = ActiveSheet
lr = Cells(Rows.Count, 1).End(xlUp).Row
If lr < 2 Then lr = 2
Set myrange = Range("a1:e" & lr)
For i = 2 To lr
If Cells(i, 2) <> "" Then GoTo 1
If movrange Is Nothing Then
Set movrange = Cells(i + 1, 2)
Else
Set movrange = Union(movrange, Cells(i, 2))
End If
1:
Next
movrange.EntireRow.Delete
''''''''''''''''''''''''''
lr1 = ws.Cells(Rows.Count, 1).End(xlUp).Row
ActiveWorkbook.Worksheets("Sheet1 (3)").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1 (3)").Sort.SortFields.Add Key:=Range("B2") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1 (3)").Sort
.SetRange Range("A2:E" & lr1)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub