0
我想寫一個VBA代碼來選擇一組具有相同值和顏色的單元格。使用VBA根據相同的值選擇一組單元格
對於A行,工作人員ID,都是一樣的,爲同一人,我希望通過他們進行掃描,如果他們是相同的,填補了細胞與淡藍色的顏色,你在看上面的圖片,列A到當前區域的最大列。
我有一個代碼來做到這一點,但是當我運行它時,它什麼都不做。任何幫助將不勝感激:
Sub ActualColouring()
Dim SerialNumber As Integer
SerialNumber = 2 'this variable will be assign to the rows, ignore the header, start from 2
Do While Cells(1, SerialNumber).Value <> "" 'keep looping as long as cell is not blank
If Cells(1, SerialNumber).Value = Cells(1, SerialNumber + 1).Value Then 'if the value of the cell is the same as the cell below, then
Cells(1, SerialNumber).Select 'then select it
With Selection.Interior 'this line is the start of the fill colouring
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With 'end of fill colouring function
End If
SerialNumber = SerialNumber + 1 'move to the next cell
Loop 'loop until the end of current region
End Sub
感謝斯科特!你是一個拯救生命的人! :) –