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

كود تصميم زر اخفاء واظهار صفوف محددة


BoShibh
إذهب إلى أفضل إجابة Solved by lionheart,

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

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

اخواني احتاج مساعدتكم في كود يظهر ويخفي لي صفوف محدده عن طريق زر Toggle انا صممته ( سحب يمين ويسار ) ولكن الكود يظهر اخطا كثيرة

Sub ToggleButto()

    Dim ws As Worksheet
    
    Dim xCells As String
    
    xCells = "12" 'change this to the row numbers

    Set ws = ThisWorkbook.ActiveSheet
    
    With ws
        
        'TOGGLE "ON"
        If ToggleButton1.Value = True Then
            
            Application.ActiveSheet.Rows(xCells).Hidden = "True"
            
            'update textbox value
            .Shapes("txtboxOnOff").TextFrame.Characters.Text = "OFF"
            
            'update textbox alignment
            .Shapes("txtboxOnOff").TextFrame.HorizontalAlignment = xlHAlignRight
            
            'update button background color
            .Shapes("ToggleButton").Fill.ForeColor.RGB = RGB(232, 27, 34)
            
            'update radio button location
            .Shapes("radioButton").Left = .Shapes("ToggleButton").Left + .Shapes("ToggleButton").Width - .Shapes("radioButton").Width - 5
            
        Else
            'TOGGLE "OFF"
            
            ToggleButton1.Value = True
            
            Application.ActiveSheet.Rows(xCells).Hidden = "False"
                
            .Shapes("txtboxOnOff").TextFrame.Characters.Text = "ON"
            
            .Shapes("txtboxOnOff").TextFrame.HorizontalAlignment = xlHAlignLeft
            
            .Shapes("ToggleButton").Fill.ForeColor.RGB = RGB(117, 199, 1)
            
            .Shapes("radioButton").Left = .Shapes("ToggleButton").Left + 5
        End If
    
    End With

    Set ws = Nothing

End Sub

مرفق لكم ملف العمل

CoCo.xlsm

رابط هذا التعليق
شارك

  • أفضل إجابة

Try this code

Sub ToggleButton_ON_OFF()
    Const ONKEY As String = "On", OFFKEY As String = "Off"
    Dim ws As Worksheet, shOnOff As Shape, shToggle As Shape, shRadio As Shape, s As String
    Set ws = ActiveSheet
    With ws
        Set shOnOff = .Shapes("txtboxOnOff")
        Set shToggle = .Shapes("ToggleButton1")
        Set shRadio = .Shapes("radioButton")
    End With
    With shOnOff
        s = .TextFrame.Characters.Text
        .TextFrame.Characters.Text = IIf(s = ONKEY, OFFKEY, ONKEY)
        ws.Rows("12").Hidden = (s = OFFKEY)
        .TextFrame.HorizontalAlignment = IIf(s = ONKEY, xlHAlignLeft, xlHAlignRight)
        shToggle.Fill.ForeColor.RGB = IIf(s = ONKEY, RGB(232, 27, 34), RGB(117, 199, 1))
        shRadio.Left = shToggle.Left + IIf(s = ONKEY, shToggle.Width - shRadio.Width - 5, 5)
    End With
End Sub

 

  • Like 5
رابط هذا التعليق
شارك

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