我是VBA編碼新手,請幫助我創建一個符合以下條件的VBA腳本。如何使用vba突出顯示小數或小於3且大於6的字符的單元格?
- 應突出顯示包含小數的單元格。
- 應該突出顯示字符數小於3或大於6的單元格。
- 應該從列G(G1)執行直到最後一行最後使用的單元格。
我的數據是字母數字或數字。
我試過使用characters.count
和Value.count
但它沒有解決。希望它能與len
一起工作,但我不確定如何開始。
附件是樣品excel文件與顯現細胞
我曾嘗試下面的代碼。由於我的數據是字母數字,所以字符數不會有幫助。
Sub HighlightCells()
Range(" G1").Select
Do
If ActiveCell.Characters.Count < 3 Then
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
ActiveCell.Offset(0, 1).Select 'need to run in every row till the last row last used cell
Loop Until ActiveCell = ""
Range(" G1").Select
Do
If ActiveCell.Characters.Count > 6 Then
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
ActiveCell.Offset(0, 1).Select 'need to run in every row till the last row last used cell
Loop Until ActiveCell = ""
End Sub
的條件是***和***條件或*** *** OR條件??? –
如果包含***沒有***字符,您希望單元格突出顯示嗎? –
條件僅限OR。沒有字符的空白單元不需要突出顯示。 – Mahesh