تم تنقيح الكود لتسهيل التعديل عليه
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Row As Integer, Col As Integer
Dim fRow As Integer, fCol As Integer, fdd As Integer
Dim yy As Integer, mm As Integer, dd As Integer
Dim cellDate As Date, DateRange As String, m
m = Array("", "يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", _
"يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر")
With Target
DateRange = Replace(.Address, "$", "")
If DateRange <> "M1" Then 'تبديل عنوان خلية التاريخ عند الحاجة'
Beep
'MsgBox
Exit Sub
End If
If Not IsDate(Range(DateRange)) Then
Beep
'MsgBox
Exit Sub
End If
Application.EnableEvents = False
Application.ScreenUpdating = False
yy = Year(.Value)
mm = Month(.Value)
For fdd = 1 To 7
If Weekday(DateSerial(yy, mm, fdd)) = vbSunday Then Exit For
Next fdd
End With
Cells.Find(What:="الأحد", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
fRow = ActiveCell.Row
fCol = ActiveCell.Column + 1
Cells(fRow - 2, fCol + 5) = m(mm)
dd = fdd - 3
For Col = fCol To fCol + 9 Step 2
dd = dd + 2
For Row = fRow To fRow + 4
dd = dd + 1
cellDate = DateSerial(yy, mm, dd)
If Month(cellDate) = mm Then
Cells(Row, Col + 0) = cellDate
Cells(Row, Col + 1) = 1
Else
Cells(Row, Col + 0) = ""
Cells(Row, Col + 1) = ""
End If
Next Row
Next Col
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
حساب_التاريخ_06.xlsm