VBA-清除先前填充的单元格的内容

时间:2012-07-04 06:40:36

标签: excel-vba vba excel

我有2列表,列为Bunker索引和Bunker名称..我必须使用VBA索引Bunker,然后生成另一个表,其中列为Bunker名称,第一列为日期... 在更改掩体数量时(例如从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

1 个答案:

答案 0 :(得分:0)

而不是.clear.clearcontents尝试:

.Interior.Pattern = xlNone