0
私はいくつかの範囲(rngSrcとrngTgt)を渡す必要がある次のコードを持っています。本質的にはいくつかの範囲の内容を別のサブに渡す
Sub Con_CCC()
Dim arr, rngSrc As Range, rngTgt As Range, rng As Range, cell As Range
Dim c As ColorStop
Dim isGreen As Boolean
Dim e As Long
Worksheets("Index Changes").Range("P7:P24").ClearContents
Set rngSrc = Sheets("Output").Range("J13:J100")
Set rngTgt = Sheets("Index Changes").Range("Y7")
For Each cell In rngSrc
isGreen = False
On Error Resume Next
With cell.Interior.Gradient.ColorStops
End With
e = Err.Number
On Error GoTo 0
If e = 0 Then
For Each c In cell.Interior.Gradient.ColorStops
arr = LongToRGB(c.Color)
If arr(2)/IIf(arr(1) = 0, 1, arr(1)) > 1.25 And arr(2)/IIf(arr(3) = 0, 1, arr(3)) > 1.25 Then
isGreen = True
Exit For
End If
Next c
Else
arr = LongToRGB(cell.Interior.Color)
If arr(2)/IIf(arr(1) = 0, 1, arr(1)) > 1.25 And arr(2)/IIf(arr(3) = 0, 1, arr(3)) > 1.25 Then isGreen = True
End If
If isGreen Then
If rng Is Nothing Then Set rng = cell.Offset(, -1).Resize(, 2) Else Set rng = Union(rng, cell.Offset(, -1).Resize(, 2))
End If
Next cell
If Not rng Is Nothing Then rng.Copy: rngTgt.PasteSpecial xlPasteValues
End Sub
私は次のコードが含まれ、その後、私の他のサブ年代の異なるrngSrcとrngTgtセットを取り、サブが必要になります。
For Each cell In rngSrc
isGreen = False
On Error Resume Next
With cell.Interior.Gradient.ColorStops
End With
e = Err.Number
On Error GoTo 0
If e = 0 Then
For Each c In cell.Interior.Gradient.ColorStops
arr = LongToRGB(c.Color)
If arr(2)/IIf(arr(1) = 0, 1, arr(1)) > 1.25 And arr(2)/IIf(arr(3) = 0, 1, arr(3)) > 1.25 Then
isGreen = True
Exit For
End If
Next c
Else
arr = LongToRGB(cell.Interior.Color)
If arr(2)/IIf(arr(1) = 0, 1, arr(1)) > 1.25 And arr(2)/IIf(arr(3) = 0, 1, arr(3)) > 1.25 Then isGreen = True
End If
If isGreen Then
If rng Is Nothing Then Set rng = cell.Offset(, -1).Resize(, 2) Else Set rng = Union(rng, cell.Offset(, -1).Resize(, 2))
End If
Next cell
If Not rng Is Nothing Then rng.Copy: rngTgt.PasteSpecial xlPasteValues
、あなたはそれを介して取得しましたか? – user3598756
@ Jeweller89、あなたを助けようとしている人々に適切なフィードバックを与えてくれてうれしいです。ありがとうございました – user3598756