0

ActiveX チェックボックス名の配列の作成に問題があります。この配列を作成して、各チェックボックス コードを個別に入力する代わりに For ループを使用できるようにします。これが私のコードの一部です。私が得ているエラーは、タイプの不一致を示し、& を強調表示します。これがうまくいく方法は、array(0) = ThirteenJan、array(1) = ThirteenFeb などです。

Dim Month(0 To 11) As String
Dim Year(0 To 3) As String
Dim Time(0 To 47) As CheckBox
Dim i, j, k, l, m As Integer

'月の初期値は、ボタンの名前がそのようになっているため、このように命名されました'初期値 Month(0) = "Jan" Month(1) = "Feb" Month(2) = "Mar" Month(3) = "4月" Month(4) = "5月" Month(5) = "6月" Month(6) = "7月" Month(7) = "8月" Month(8) = "9月" Month(9) = " 10 月" Month(10) = "11 月" Month(11) = "12 月"

Year(0) = "Thirteen"
Year(1) = "Fourteen"
Year(2) = "Fifteen"
Year(3) = "Sixteen"

k = 0

'I can't get the following code to work and I'm not sure what's wrong with it. It says     type mismatch and highlights the &.
'Create an array that has all the names of the checkboxes in each element of it
For i = 0 To 3
    For j = 0 To 11
        Set Time(k) = Year(i) & Month(j)
    k = k + 1
    Next j
    k = k + 1
Next i

k = 4
l = 18

For i = LBound(Time) To UBound(Time)
    'j loops through worksheets, the summary sheets are organized differently than the     rest of the workbook so they have to have their own code
    For j = 2 To 3
        'k loops through the columns, 54 is Column BB
        If k = 16 Or k = 29 Or k = 42 Then
        k = k + 1
        End If
        If Time(i).Value = True Then
            Sheets(j).Columns(k).EntireColumn.Hidden = False
        Else
            Sheets(j).Columns(k).EntireColumn.Hidden = True
        End If
    Next j
    For j = 4 To 9
        If l = 30 Or l = 31 Or l = 44 Or l = 45 Or l = 58 Or l = 59 Then
            l = l + 1
        End If
4

1 に答える 1

0
Sub Macro1()
        Dim MyCheckboxes(1 To 10) As OLEObject
        Dim shp As Shape
        Range("A1").Select
        For i = 1 To 10
            ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
                DisplayAsIcon:=False, Left:=240, Top:=75.75, Width:=49.5, Height:= _
                17.25).Select
            Set MyCheckboxes(i) = Selection
            Set shp = ActiveSheet.Shapes("CheckBox" & i)
            shp.Left = ActiveCell.Left
            shp.Top = ActiveCell.Top
            shp.Height = ActiveCell.Height
            shp.Width = ActiveCell.Width
            ActiveCell.Offset(2, 0).Select
        Next
    End Sub
于 2013-06-17T18:33:48.930 に答える