1
我有一个循环放置在Excel工作表中的每个第10个条目上的粗体字体,但是我想要每20个条目的粗体字体。我该如何解决这个问题?任何帮助是极大的赞赏。VBA:使每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
改变'for ... next'迭代的方式,比如'For i = 3 To counter - 1 Step 20'。这将通过消除检查你是否在正确的行上的必要性来加速日常工作。 – Jeeped
感谢您的帮助。这在某种程度上是有效的,但现在它也停止了对第20项的大胆介入。 –
不确定我完全理解,但它看起来像你正在选择每10行进行处理 - 也就是说,它看起来像你期望第一列包含连续的数字,所以'如果Cells(i,1).Value Mod 10 = 8'选择值为8,18,28等的行。这可以解释为什么@Jeeped的建议导致粗体停止。我认为你需要更好地解释你的目标,以获得良好的帮助。 – vknowles