Excelがこのコードを気に入らない理由を理解できず、トラブルシューティングの方法に関する私の(だが)制限された知識をすべて踏襲しました。Excelエラー424ヘルプが必要
私のコードは、null範囲と重複を処理するはずのオンラインで見つかったProperUnionコードを呼び出します。私はコードの2番目のビットがどのように機能するかについての基本的な把握しかありません。最初のビットはすべて私のものです。
このコードでは、フラグが設定されているかどうかに基づいて項目のリストを選択し、各フラグを範囲として保存してから、必要に応じて交差させます。私がテストしているケースでは、問題を引き起こしている可能性のある「フラグ3」ボックスのみがチェックされています。
私は、デバッグエラーを与えている正しいユニオンの行に「xxxxxxx」を挿入します。
何かすべてのヘルプは大歓迎です。
からフラグ付きの情報コード
Sub GSFlagged(prg As String) 'prg is the Program Name
Dim rng As Range
Dim rngA As Range
Dim rngx(1 To 8) As Variant
Dim rngu As Range
Dim r As Long
Dim wsMaster As Worksheet
Dim wsGenScore As Worksheet
Dim wsScore As Worksheet
Set wsMaster = Worksheets("Master List")
Set wsGenScore = Worksheets("Generate Scorecard")
Set wsScore = Worksheets("Scorecard")
wsMaster.Activate
'Make sure that the master list is not filtered
If wsMaster.AutoFilterMode = True Then
wsMaster.AutoFilterMode = False
End If
'Select all data in the Masterlist and then remove the headers
Set rng = wsMaster.Range("B4:E4", Range("B4:E4").End(xlDown))
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
'Filter by the program name
wsMaster.Range("B4").AutoFilter Field:=2, Criteria1:=prg
Set rngA = rng.SpecialCells(xlCellTypeVisible)
'Filter by flags with a loop over the variable r and save each set of visible cells as rngx(r)
For r = 1 To 8
If wsGenScore.Shapes("Flag" & r).ControlFormat.Value = 1 Then
wsMaster.Activate
If wsMaster.AutoFilterMode = True Then
wsMaster.AutoFilterMode = False
End If
wsMaster.Range("B4").AutoFilter Field:=r + 6, Criteria1:="<>"
Set rngx(r) = rng.SpecialCells(xlCellTypeVisible)
End If
Next r
'After filtering through all the SKUs we union them using Proper Union a Custom VBA that allows for null values and removes duplicates.
Set rngu = ProperUnion(rngx(1), rngx(2), rngx(3), rngx(4), rngx(5), rngx(6), rngx(7), rngx(8))
'Now that we have rngu which is the union of all flagged SKUs we want to intersect that with the SKUs that are in the chosen program.
Set rngi = Intersect(rngA, rngu)
End Sub
適切な連合コード を収集します。あなたはVariant
配列するrngx
を宣言したが、それはRange
オブジェクトの配列として宣言する必要がありますhttp://www.cpearson.com/Excel/BetterUnion.aspx
Function ProperUnion(ParamArray Ranges() As Variant) As Range
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ProperUnion
' This provides Union functionality without duplicating
' cells when ranges overlap. Requires the Union2 function.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ResR As Range
Dim n As Long
Dim r As Range
If Not Ranges(LBound(Ranges)) Is Nothing Then 'xxxxxxxxxx
Set ResR = Ranges(LBound(Ranges))
End If
For n = LBound(Ranges) + 1 To UBound(Ranges)
If Not Ranges(n) Is Nothing Then
For Each r In Ranges(n).Cells
If Application.Intersect(ResR, r) Is Nothing Then
Set ResR = Union2(ResR, r)
End If
Next r
End If
Next n
Set ProperUnion = ResR
End Function
'Union2 is required for ProperUnion
Function Union2(ParamArray Ranges() As Variant) As Range
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Union2
' A Union operation that accepts parameters that are Nothing.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim n As Long
Dim RR As Range
For n = LBound(Ranges) To UBound(Ranges)
If IsObject(Ranges(n)) Then
If Not Ranges(n) Is Nothing Then
If TypeOf Ranges(n) Is Excel.Range Then
If Not RR Is Nothing Then
Set RR = Application.Union(RR, Ranges(n))
Else
Set RR = Ranges(n)
End If
End If
End If
End If
Next n
Set Union2 = RR
End Function
requiremens - [出典:www.cpearson.com/Excel/BetterUnion.aspx Copyright 2013、Charles H. Pearson](http://www.cpearson.com)のサイトを満たすために、「ProperUnion」のソースを引用する必要があります。 /Excel/BetterUnion.aspx) –
大変申し訳ございません。私はそのルールを忘れてしまった。私はそれを私のプロジェクトのトップモジュールで引用しましたが、ここでそれをリンクするのを忘れました。それについて言及してくれてありがとうございます。今すぐ投稿に追加します。 –