0
我想通過VBA在Excel中基於它們的格式對行進行分組,並且在谷歌搜索時發現了一個2005年的論壇帖子,其中提出了類似的問題。
用戶發佈的代碼對於選擇行非常適用,但我無法獲得代碼來實際分組行。基於格式的VBA分組行
代碼:
Sub GetSameFormattedRange()
Dim c As Range, r As Range, e As Range
Set e = Intersect(ActiveSheet.UsedRange, Columns(1))
SetFormatData
Set c = e.Find(What:="", SearchFormat:=True)
If Not c Is Nothing Then
Set r = c
firstAddress = c.Address
Do
Set r = Union(r, c)
Set c = e.FindNext(After:=c)
If Not c Is Nothing Then
If c.Address = firstAddress Then Exit Do
End If
Loop While Not c Is Nothing
End If
If Not r Is Nothing Then
MsgBox r.Address
End If
Application.FindFormat.Clear
End Sub
Sub SetFormatData()
Application.FindFormat.Clear
Application.FindFormat.Interior.Color = vbRed
Application.FindFormat.Locked = True
Application.FindFormat.FormulaHidden = False
End Sub
在我的情況Application.FindFormat.Interior.Color = vbRed
將Application.FindFormat.IndentLevel = 1
謝謝!
太棒了!必須調整一下,但非常感謝答案。花幾個小時試圖找到一個更復雜的方式來做到這一點。 – GenTugorn