2017-03-02 11 views
0

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 
+1

requiremens - [出典:www.cpearson.com/Excel/BetterUnion.aspx Copyright 2013、Charles H. Pearson](http://www.cpearson.com)のサイトを満たすために、「ProperUnion」のソースを引用する必要があります。 /Excel/BetterUnion.aspx) –

+0

大変申し訳ございません。私はそのルールを忘れてしまった。私はそれを私のプロジェクトのトップモジュールで引用しましたが、ここでそれをリンクするのを忘れました。それについて言及してくれてありがとうございます。今すぐ投稿に追加します。 –

答えて

1

そうであることを宣言を変更:

Dim rngx(1 To 8) As Range 

として、現在書かれ、rngxの割り当てられていない要素は、それがクラッシュした理由である、Variant/Emptyの種類とProperUnionに渡されています。 rngxRangeに変更すると、パラメータはVariant/Rangeとして渡され、割り当てられていない要素はNothingになります。

+0

Hmmm ....ここで、エラー5:無効なプロシージャが表示されます。「Application.Intersect(ResR、r)がNothing Then」の場合、最初の質問は解決しましたので、私ができる時の答え。 –

+1

'Application.Intersect'は' Nothing'をパラメータの1つとして受け入れないので、 'ProperUnion'は' Nothing'を最初の範囲として使うことはできません。私はそれを変更する必要があると思う 'If ResR Is Nothing Then' Set ResR = r'' ElseIf Application.Intersect(ResR、r)Nothing Then'' Set ResR = Union2(ResR、r) '' End If'。 – YowE3K

+0

これは完璧に動作します!どうもありがとうございました! –

関連する問題