0

我有 2 个列作为掩体索引和掩体名称的列表。我必须使用 VBA 索引掩体,然后生成另一个表,其中列作为掩体名称和“第一列作为日期……关于更改掩体的数量(比如从 10 到 8).. 第二个表中单元格的颜色(最后 2 列预先填充)保持不变(蓝色),我需要默认(白色)

我使用了工作簿中的许多变量。这方面的任何建议。至于格式化应该怎么做?

这是代码:

Sub Bunker_index_Click()
    Sheet3.Range(Sheet3.Cells(4, 6), Sheet3.Cells(500, 100)).ClearContents

    Dim N As Integer
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim LocalIYM As Date
    LocalIYM = ThisWorkbook.IYM
    N = Application.CountA(Range("B:B")) - 1
    ThisWorkbook.NumBunker = N
    MsgBox (N)
    Cells(5, 1).Value = "Bunker Index"

    For i = 1 To 100
        If i <= N Then
            Cells(5 + i, 1).Value = i
            Cells(5 + i, 1).Interior.Color = RGB(253, 233, 217)
            Cells(5 + i, 2).Interior.Color = RGB(219, 238, 243)
        Else
            Cells(5 + i, 1).ClearContents
            Cells(5 + i, 2).ClearContents

        End If

    Next i

        Range("F5").Value = "Time (LOCKED)"
        Range("F5").Interior.Color = RGB(253, 233, 217)
        For i = 1 To 100
            If i <= N Then
                Cells(5, 6 + i).Value = Cells(5 + i, 2)
                Cells(5, 6 + i).Interior.Color = RGB(253, 233, 217)
            Else
                Cells(5, 6 + i).ClearContents         ' unable to bring back th original
                                                      ' color of the cells

            End If

        Next i

    For k = 1 To 12 * 1
        If k <= ThisWorkbook.N Then
             Cells(k + 5, 6).Value = LocalIYM
             LocalIYM = DateAdd("m", 1, LocalIYM)
             Cells(5 + k, 6).Interior.Color = RGB(253, 233, 217)            ' problem handling borders
           '  Range("B2").Borders(xlEdgeLeft).LineStyle = XlLineStyle.xlDashDot

         '    1edgeleft).LineStyle = x1linestyle.x1countinous

             For j = 1 To N
                Cells(5 + k, 6 + j).Interior.Color = RGB(219, 238, 243)
             Next j

        Else
             Sheet2.Cells(i + 4, 6).Clear
        End If
    Next k
End Sub
4

1 回答 1

0

代替.clear.clearcontents尝试:

.Interior.Pattern = xlNone
于 2012-07-05T09:59:35.620 回答