我编写了以下VBA代码来重绘表格的边框。我还编写了一些小的测试代码,以根据B84的值对单元格B11和B12应用条件格式。如果B84的值= 1,那么我想在B11和B12中填充黄色。但这不起作用。
如果这行得通,我想写更多的条件,例如,如果C84 = 1,则C11和C12将用黄色填充,以此类推,如果R84 = 1,直到R11和R12将用黄色填充。
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
ReInstateBorders Range("A7:R16,A18:R23")
Application.ScreenUpdating = True
End Sub
Sub ReInstateBorders(theRange)
For Each are In theRange.Areas
For rw = 1 To are.Rows.Count - 1 Step 2
For colm = 1 To are.Columns.Count
are.Cells(rw, colm).Resize(2).BorderAround xlContinuous
Next colm
Next rw
Next are
If Sheets("timetable").Range("B84").Value = 1 Then
Sheets("timetable").Range("B11").Interior.Color = vbYellow
Sheets("timetable").Range("B12").Interior.Color = vbYellow
End If
End Sub