I have 2 column table with columns as bunker index and bunker name.. i have to index the bunker using VBA and then generate another table with columns as the Bunker names and 'first column as the date... On changing the number of bunkers( like from 10 to 8).. the color of the cells(last 2 columns previosly filled) in second table remains the same (blue), which i require as default (white)
I have used many variables from my workbook. Any suggestion in this regard. As to how should the formatting be done?
This is the Code :
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
代替.clear
或.clearcontents
尝试:
.Interior.Pattern = xlNone
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.