在Userform链接复选框中,带有选项按钮

时间:2017-04-16 07:46:40

标签: vba checkbox

我创建了一个用户窗体(用于更改活动工作表或所有工作表的列宽和行宽),该窗体具有三个框架。在第一帧中,我给了两个选项框。第一个选项框: - 从列B向前更改行和列宽度以及其他选项框以从列c开始更改行列宽。用户将选择其中任何一个,然后移动到第二帧:再次有两个选项,一个用于在活动工作表和第二个选项框中进行更改,以在所有工作表中进行更改。因此,如果第一种形式的用户将选择第一个选项(从B开始更改行和列宽度,在第二个框架中将选择活动工作表,那么列和行宽将从活动工作表中的B列开始改变,依此类推。 ..

现在我要创建第三个fram,其中有3个复选框,其名称为3张(Sheet1,Sheet2和Sheet3。)我希望当用户在第一帧和第二帧中选择他的选项时,如果用户在第三帧中选中任何复选框或所有复选框,然后更改不应适用于他选择的3个复选框中提到的工作表名称。

我已成功执行第一帧和第二帧但是很难为第3帧创建一个代码,该代码将包含3个复选框(其中包含3张名称),这些复选框将被排除以进行任何行和列宽度的更改。

请在下面找到我在模块中的代码

Sub rowcolactivesheetb()
    Dim exworkb As Workbook
    Dim xlwksht As Worksheet
    Dim lastrow1 As Long
    Dim lastcolumn1 As Long
    Dim firstrowDB As Long
        With ActiveSheet
            lastrow1 = .Cells(Rows.Count, "A").End(xlUp).Row
            lastcolumn1 = .Cells(1, Columns.Count).End(xlToLeft).Column
            .Range(.Cells(1, 2), .Cells(lastrow1, lastcolumn1)).Select
            Selection.Cells.RowHeight = 9.14
            Selection.Cells.ColumnWidth = 7.14
        End With
End Sub

Sub rowcolallsheetb()
    Dim exworkb As Workbook
    Dim xlwksht As Worksheet
    Dim lastrow1 As Long
    Dim lastcolumn1 As Long
    Dim firstrowDB As Long
    Dim Z As Integer
    Dim ShtNames() As String

    ReDim ShtNames(1 To ActiveWorkbook.Sheets.Count)
    For Z = 1 To Sheets.Count
        ShtNames(Z) = Sheets(Z).Name
        Sheets(Z).Select
        lastrow1 = Sheets(Z).Cells(Rows.Count, "A").End(xlUp).Row
        lastcolumn1 = Sheets(Z).Cells(1, Columns.Count).End(xlToLeft).Column
        ActiveWorkbook.Sheets(Z).Range(Sheets(Z).Cells(1, 2), Sheets(Z).Cells(lastrow1, lastcolumn1)).Select
        Selection.Cells.RowHeight = 9.14
        Selection.Cells.ColumnWidth = 7.14
    Next Z
End Sub

Sub rowcolactivesheetc()
    Dim exworkb As Workbook
    Dim xlwksht As Worksheet
    Dim lastrow1 As Long
    Dim lastcolumn1 As Long
    Dim firstrowDB As Long
    With ActiveSheet
        lastrow1 = .Cells(Rows.Count, "A").End(xlUp).Row
        lastcolumn1 = .Cells(1, Columns.Count).End(xlToLeft).Column
        .Range(.Cells(1, 3), .Cells(lastrow1, lastcolumn1)).Select
        Selection.Cells.RowHeight = 9.14
        Selection.Cells.ColumnWidth = 7.14
    End With
End Sub

Sub rowcolallsheetc()

    Dim exworkb As Workbook
    Dim xlwksht As Worksheet
    Dim lastrow1 As Long
    Dim lastcolumn1 As Long
    Dim firstrowDB As Long
    Dim Z As Integer
    Dim ShtNames() As String

    ReDim ShtNames(1 To ActiveWorkbook.Sheets.Count)

    For Z = 1 To Sheets.Count

        ShtNames(Z) = Sheets(Z).Name

        Sheets(Z).Select

        lastrow1 = Sheets(Z).Cells(Rows.Count, "A").End(xlUp).Row

        lastcolumn1 = Sheets(Z).Cells(1, Columns.Count).End(xlToLeft).Column

        ActiveWorkbook.Sheets(Z).Range(Sheets(Z).Cells(1, 3), Sheets(Z).Cells(lastrow1, lastcolumn1)).Select

        Selection.Cells.RowHeight = 9.14

        Selection.Cells.ColumnWidth = 7.14

    Next Z

End Sub

用户形式代码:

Private Sub CommandButton1_Click()

    If Me.OptionButton5.Value = True Then

        If Me.OptionButton7.Value = True Then

            Call rowcolactivesheetb

        ElseIf Me.OptionButton8.Value = True Then

            rowcolallsheetb

        End If

    End If

    If Me.OptionButton6.Value = True Then

        If Me.OptionButton7.Value = True Then

            Call rowcolactivesheetc

        ElseIf Me.OptionButton8.Value = True Then

            rowcolallsheetc

        End If

    End If

End Sub

0 个答案:

没有答案