Excelワークブックの1つのグループに4つの図形があります。黄色で2つの図形を表示すると、セル(6,21)が1になり、セル(6,22)が表示されます。 (9,21)はまだ2のままです。異なる色の図形グループの数を計算する
以下は私のワークブックに適用されますが動作しなかったVBAコードです私が望むように。
Private Sub Worksheet_Activate()
Dim shp As Shape
Dim shprange As ShapeRange
Dim CountyellowShape As Long
Dim CountorangeShape As Long
Dim CountpinkShape As Long
Dim CountblueShape As Long
For Each shp In Sheet1.Shapes
If shp.Type = msoGroup Then
Set shprange = shp.Ungroup
Set oMyGroup = shprange.Group
If shprange.Fill.ForeColor.RGB = RGB(255, 255, 0) Then CountChildShapeYELLOW = CountChildShapeYELLOW + 0.5
If shprange.Fill.ForeColor.RGB = RGB(255, 153, 0) Then CountChildShapeORANGE = CountChildShapeORANGE + 0.5
If shprange.Fill.ForeColor.RGB = RGB(255, 102, 153) Then CountChildShapePINK = CountChildShapePINK + 0.5
If shprange.Fill.ForeColor.RGB = RGB(0, 176, 240) Then CountChildShapeBLUE = CountChildShapeBLUE + 0.5
End If
Next shp
For Each shp In Sheet1.Shapes
If shp.Fill.ForeColor.RGB = RGB(255, 255, 0) Then CountShapeYELLOW = CountShapeYELLOW + 0.5
If shp.Fill.ForeColor.RGB = RGB(255, 153, 0) Then CountShapeORANGE = CountShapeORANGE + 0.5
If shp.Fill.ForeColor.RGB = RGB(255, 102, 153) Then CountShapePINK = CountShapePINK + 0.5
If shp.Fill.ForeColor.RGB = RGB(0, 176, 240) Then CountShapeBLUE = CountShapeBLUE + 0.5
Next shp
Sheet1.Cells(6, 21) = CountShapeYELLOW + CountChildShapeYELLOW
Sheet1.Cells(7, 21) = CountShapeORANGE + CountChildShapeORANGE
Sheet1.Cells(8, 21) = CountShapePINK + CountChildShapePINK
Sheet1.Cells(9, 21) = CountShapeBLUE + CountChildShapeBLUE
For Each shp In Sheet1.Shapes
If shp.Type = msoGroup Then
Set shprange = shp.Ungroup
For Each grpShp In shprange
If grpShp.Fill.ForeColor.RGB = RGB(255, 255, 0) Then CountChildShapeYELLOW = CountChildShapeYELLOW + 0.5
If grpShp.Fill.ForeColor.RGB = RGB(255, 153, 0) Then CountChildShapeORANGE = CountChildShapeORANGE + 0.5
If grpShp.Fill.ForeColor.RGB = RGB(255, 102, 153) Then CountChildShapePINK = CountChildShapePINK + 0.5
If grpShp.Fill.ForeColor.RGB = RGB(0, 176, 240) Then CountChildShapeBLUE = CountChildShapeBLUE + 0.5
Next grpShp
shprange.Group
Else
If shp.Fill.ForeColor.RGB = RGB(255, 255, 0) Then CountShapeYELLOW = CountShapeYELLOW + 0.5
If shp.Fill.ForeColor.RGB = RGB(255, 153, 0) Then CountShapeORANGE = CountShapeORANGE + 0.5
If shp.Fill.ForeColor.RGB = RGB(255, 102, 153) Then CountShapePINK = CountShapePINK + 0.5
If shp.Fill.ForeColor.RGB = RGB(0, 176, 240) Then CountShapeBLUE = CountShapeBLUE + 0.5
End If
Next shp
Sheet1.Cells(6, 22) = CountShapeYELLOW + CountChildShapeYELLOW
Sheet1.Cells(7, 22) = CountShapeORANGE + CountChildShapeORANGE
Sheet1.Cells(8, 22) = CountShapePINK + CountChildShapePINK
Sheet1.Cells(9, 22) = CountShapeBLUE + CountChildShapeBLUE
End Sub
ありがとうございます。 Wiz Lee
非常に悪い説明。私はあなたが何を望んでいるか分かりません。 「私が望むように動かなかった」と言っても、コードを実行したときに何が起こるかについては何も説明されていないので、問題の解決策を作るのには役立ちません。 ...実際には、いくつかのコードを掲示して「うまくいきません」と言いました....私が言うことは「よく、あなたのコードを変更して、あなたが望むことをする」ということです。 – jsotola
本当に残念です私の英語はとても悪く、あなたを無力にします。私はコードを実行するとき、私はグループシフトに異なる色を入れて、セル(6,21)は0に変更されます。私はセル(6,21)が1として残る必要があります。 –