-3

我想做一个 If 语句来测量自动过滤列中的字符数量,如果字符数量 (Len) = 9 或 12,我希望它转到第一列并更改该行上单元格的名称到“克洛”。我希望它运行整个列(列 M 和 N)。我该怎么做呢?

    Dim count As Integer, myRange As Range, rng As Range
Dim RealRng As Range

Set myRange = Columns("M:M")
count = Application.WorksheetFunction.CountA(myRange)
Set RealRng = ActiveSheet.Range("M2:M+" & count)
For Each rng In RealRng
    If Len(rng) = 9 Or Len(rng) = 12 Then
        rng.Offset(0, -12) = "Bond"
    End If
Next rng
4

1 回答 1

0

这是一个简单的演示,它将遍历过滤范围,测试长度,如果长度为 9 或 12,则更改下一列。

您需要根据自己的目的进行调整:

Sub Demo()
    Dim filteredRng As Range, rng As Range

    Set filteredRng = Range("A1:A10").SpecialCells(xlCellTypeVisible)

    For Each rng In filteredRng
        If Len(rng) = 9 Or Len(rng) = 12 Then
            rng.Offset(0, 1) = "CLO"
        End If
    Next rng

End Sub
于 2013-06-21T21:07:32.407 回答