اذهب الي المحتوي
أوفيسنا

الردود الموصى بها

قام بنشر

السلام عليكم و رحمة الله و بركاته 

تقبل الله صياكم 

ارجو المساعدة بماكرو يقوم عند اختيار السنة  من الخلية l1 يقوم بنعبئة التاريخ في  الخلية c5   و c4   اليوم  من بداية العام  الى اخره 

مثال اذا تم اختيار السنة 2023   يقوم بتعبئة من 1/1/2023 ,  لغاية نهاية السنة 31/12/2023

و عتد اختيار الشهر  من الخلية L2  يقوم باظهار  اعمدة الشهر  المختار و اخفاء جميع الاشهر الاخري  

و جزاكم الله كل خير 

absss.xlsm

قام بنشر

السلام عليكم 

اخ @lionheart  الخلية C4   اليوم مثل السبت الاحد ...... 

                      و c5     التاريخ  مثل 1/1/2023  >>2/1/2023  3/1/2023 >>>>  الى نهاية السنة 31/12/2023

  و الخلية  l2 تقوم بعرض الشهر و اخفاء الاشهر الاخرى 

قام بنشر

But it is not practical to put the year cell and the month cell in L1 & L2 as these columns will be hidden if you select January

I suggest you rebuild the strucutre of the file so as to get the year cell and the month cell away from column C to colum NC

 

  • أفضل إجابة
قام بنشر

Suppose the cells are B1 & B2 for the year and the month, try the following code in worksheet change event

Private Sub Worksheet_Change(ByVal Target As Range)
    Const FirstRow As Long = 4, FirstColumn As Long = 3, numColumns As Long = 366, sColTarget As String = "C:ND"
    Dim results(1 To 2, 1 To numColumns), yearValue As Long, currentDate As Date, lastDate As Date, i As Long, selectedMonth As Long, col As Long
    If Target.Address = "$B$1" Then
        If Target.Value = Empty Then Columns(sColTarget).Rows(FirstRow & ":" & FirstRow + 1).ClearContents: GoTo Skipper
        On Error Resume Next
            yearValue = CInt(Target.Value)
        On Error GoTo 0
        If IsDate("01/01/" & yearValue) Then
            currentDate = DateSerial(yearValue, 1, 1)
            lastDate = DateSerial(yearValue + 1, 1, 1) - 1
            i = 0
            While currentDate <= lastDate
                i = i + 1
                results(1, i) = Format(currentDate, "ddd")
                results(2, i) = Format(currentDate, "yyyy-mm-dd")
                currentDate = currentDate + 1
            Wend
            Application.EnableEvents = False
            Application.ScreenUpdating = False
                Range(Cells(FirstRow, FirstColumn), Cells(FirstRow + 1, FirstColumn + i - 1)).Value = results
            Application.ScreenUpdating = True
            Application.EnableEvents = True
        Else
            MsgBox "Please Enter Valid Year", vbExclamation
        End If
    ElseIf Target.Address = "$B$2" Then
        If Target.Value = Empty Then GoTo Skipper
        On Error Resume Next
            selectedMonth = Left(Target.Value, InStr(Target.Value, ".") - 1)
        On Error GoTo 0
        If selectedMonth <> 0 Then
            Application.EnableEvents = False
            Application.ScreenUpdating = False
                Columns(sColTarget).Hidden = True
                For col = FirstColumn To numColumns + (FirstColumn - 1)
                    If IsDate(Cells(FirstRow + 1, col).Value) Then
                        If Month(Cells(FirstRow + 1, col).Value) = selectedMonth Then Cells(FirstRow + 1, col).EntireColumn.Hidden = False
                    End If
                Next col
            Application.ScreenUpdating = True
            Application.EnableEvents = True
        End If
    End If
    Exit Sub
Skipper:
    Application.EnableEvents = False
        Columns(sColTarget).Hidden = False
    Application.EnableEvents = True
End Sub

 

  • Like 2
قام بنشر

Change thi line

If Target.Value = Empty Then Columns(sColTarget).Rows(FirstRow & ":" & FirstRow + 1).ClearContents: GoTo Skipper

To be

Columns(sColTarget).Rows(FirstRow & ":" & FirstRow + 1).ClearContents: GoTo Skipper

 

قام بنشر

Sorry

Use the line without this part

: GoTo Skipper

The line should be

Columns(sColTarget).Rows(FirstRow & ":" & FirstRow + 1).ClearContents

You have to be able to fix such issues by yourself

قام بنشر (معدل)

I think you specified the wrong reply as the best answer. This is not useful for other members

تم تعديل بواسطه lionheart

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information