簡體   English   中英

VBA:讓每個20個單元格變大膽

[英]VBA: Make every 20th cell bold

我有一個循環,在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。 相應地調整它的相等,以確保它在正確的位置開始。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM