2017-08-10 5 views
0

VBAを使用してExcelの書式設定に基づいて行をグループ化しようとしていますが、グーグルでは2005年から同様の質問が表示されます。
ユーザーが投稿したコードは、行を選択するのに最適ですが、どうやら実際に行をグループ化するコードを取得できません。VBAフォーマットに基づいた行のグループ化

Original Forum post

コード:

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 = vbRedApplication.FindFormat.IndentLevel = 1

感謝されます!

答えて

0

このあなたのために動作しない場合がありますが、私はまた.Interior.Colorのために働く必要があり.Interior.Pattern、に基づいてアイテムをグループ化されたところ、私は実際に、以前の今日似た何かをやっていた:

Dim i as Integer 
For i = 2 to 10 
    If Cells(i,1).Interior.Pattern=xlSolid Then 
     Rows(i).EntireRow.Group 
     Else 
     End If 
    Next i 

これに注意することは、各行がグループ化され、後続の行もグループ化されている場合、グループ化されてグループ化された行の合計長さが増加することです。休憩があると、新しいグループ化が開始されます。

+0

素晴らしい作品です!それを微調整しなければならなかったが、答えに感謝する。それを行うもっと複雑な方法を見つけようと時間を費やす。 – GenTugorn

関連する問題