VBA:使每20个单元格大胆

我有一个循环放置在Excel工作表中的每个第10个条目的粗体字体,但是我想在每20个条目的粗体字体。 我该如何解决这个问题? 任何帮助是极大的赞赏。

以下是我正在使用的代码:

'insert xxxx9 after xxxx8 if needed For i = 3 To counter - 1 If Cells(i, 1).Value Mod 10 = 8 Then ' counter = counter + 1 If Cells(i + 1, 1) <> Cells(i, 1) + 1 Then i = i + 1 Rows(i & ":" & i).Select Selection.Insert Shift:=xlDown Cells(i, 1) = Cells(i - 1, 1) + 1 Range("A" & 20).Select Selection.Font.Bold = True Cells(i, 2) = "900" Range("B" & i).Select Selection.Font.Bold = True Cells(i, 3) = "chk" Range("C" & i).Select Selection.Font.Bold = True Cells(i, 6) = "1" Range("F" & i).Select Selection.Font.Bold = True Else i = i + 1 Rows(i & ":" & i).Select Range("A" & i).Select Selection.Font.Bold = True End If End If Next 'count number of entries counter = 2 While (Cells(counter, 1).Value <> "" Or Cells(counter, 1).Value <> Null) counter = counter + 1 Wend 'insert xxxx9 after xxxx8 if needed For i = 3 To counter - 1 If Cells(i, 1).Value Mod 10 = 8 Then ' counter = counter + 1 If Cells(i + 1, 1) <> Cells(i, 1) + 1 Then i = i + 1 Rows(i & ":" & i).Select Selection.Insert Shift:=xlDown Cells(i, 1) = Cells(i - 1, 1) + 1 Range("A" & 20).Select Selection.Font.Bold = True Cells(i, 2) = "900" Range("B" & i).Select Selection.Font.Bold = True Cells(i, 3) = "chk" Range("C" & i).Select Selection.Font.Bold = True Cells(i, 6) = "1" Range("F" & i).Select Selection.Font.Bold = True Else i = i + 1 Rows(i & ":" & i).Select Range("A" & i).Select Selection.Font.Bold = True End If End If Next 

Mod 10正在返回除以10之后的余数。为了使条件成为每20行一次TRUE,改为使用Mod 20。 相应地调整它是否相等,以确保它在正确的位置启动。