Sub Dublikati_psihiatri_J()
'Comment marks Description:
'' (2 marks.) Instructions to K0st4din. Delete on satisfaction.
'''' (4 marks.) Section Heading or major code segment.
' (1 mark.) Programmer reason for choosing to code this way.
'' In VBA Editor, move Section Headings to far left, (Delete leading spaces.)
Const DateCol As Long = 4 ''If sheet layout changes, only change these Constants
Const NumCol As Long = 7 ''to maintain code.
Const CodeCol As Long = 10
Const ShtName As String = "my name sheet"
Dim sh As Worksheet
Dim lastrow As Long
Dim rw As Long 'Row Index
Set sh = Sheets(ShtName)
Application.ScreenUpdating = False
''''Sort for Processing
With sh
lastrow = .Cells(Rows.Count, "J").End(xlUp).Row
'Changed Sort Order1 to Descending to preserve "no delete" rows
Range("A1").CurrentRegion.Sort Key1:=Columns(NumCol), Order1:=xlDescending, _
Key2:=Columns(CodeCol), Order2:=xlAscending, _
Key3:=Columns(DateCol), Order3:=xlAscending, _ ' here makes ordering range A through J - exactly as it should be, but how this layout making
Header:=xlYes ' me move information for each row to AC?
'''''Processing. Delete Rows per Criteria.
For rw = lastrow To 2 Step -1
'Fixed Cell assignments. Column J is not Columns(11)
If .Cells(rw, CodeCol).Value = .Cells(rw - 1, CodeCol).Value _
And .Cells(rw, NumCol).Value = .Cells(rw - 1, NumCol).Value Then
'Next line Raises "Type Mismatch" Error when Anded with above?!?!
If Month(.Cells(rw, DateCol).Value) = Month(.Cells(rw - 1, DateCol).Value) Then
'Edit Resize as needed
.Cells(rw, 1).Resize(1, CodeCol + 19).Delete Shift:=xlUp 'here delete to column AC and is correctly
End If
End If
Next rw
''''Restore sort for viewing.
'' Adjust sort as desired
Range("A1").CurrentRegion.Sort Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Columns(DateCol), Order2:=xlAscending, _
Key3:=Columns(NumCol), Order3:=xlAscending, _
Header:=xlYes
End With
Application.ScreenUpdating = True
End Sub