如何用小数点或小于3和大于6的字符使用vba来突出显示单元格?

我是VBA编码的新手,请帮助我创build一个VBA脚本,并具备以下条件。

  1. 应突出显示包含小数的单元格。
  2. 应突出显示字符数小于3或大于6的单元格。
  3. 应该从列G(G1)执行到最后一行最后使用的单元格。

我的数据是字母数字或数字。

我已经尝试使用characters.countValue.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 

之前:

在这里输入图像说明

这段代码几乎可以直接将你的描述翻译成VBA:

 Sub Dural() Dim N As Long, i As Long, s As String, L As Long N = Cells(Rows.Count, "G").End(xlUp).Row For i = 1 To N s = Cells(i, "G").Text L = Len(s) If InStr(1, s, ".") > 0 Or (L < 3 Or L > 6) Then With Cells(i, "G").Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 .PatternTintAndShade = 0 End With End If Next i End Sub 

之后:

在这里输入图像说明

 Sub Test() Application.ScreenUpdating = False LastRow = Rows(ActiveSheet.UsedRange.Row + _ ActiveSheet.UsedRange.Rows.Count - 1).Row LastCol = Columns(ActiveSheet.UsedRange.Column + _ ActiveSheet.UsedRange.Columns.Count - 1).Column For Each cll In Range(Cells(1, 7), Cells(LastRow, LastCol)) s = cll.Value l = Len(s) If ((l > 0) And (l < 3)) Or (l > 6) Or (s Like "*#.#*") _ Then cll.Interior.Color = vbRed Next cll Application.ScreenUpdating = True 

结束小组