2016-07-13 5 views
0

ユーザーは、チェックボックスを使用して、必要なオプションを選択します。各チェックボックスのキャプション値は動的配列に格納され、メッセージボックスに表示され、選択を確認します。ダイナミックアレイ(vba)の値による検索

ここで、cell(x、4)が配列内の任意の値と等しいかどうかを判断するすべての行で、セルの範囲をループする必要がありますが、そのようにループする方法はわかりません。配列にデータが格納されている場所のコードを参照してください。

ありがとうございます!

Sub ProcessStrats_Click() 
Dim ctl As Control 
Dim cnt As Long 
Dim msg As String 
Dim i As Long 
Dim cResp As Integer 
Dim stArray() As Variant 

    cnt = 0            'Initialize counter outside of loop 
    For Each ctl In StratFill.Controls     'look at every control in StratForm box 
     If Left(ctl.Name, 8) = "CheckBox" Then   'if the control is named 'checkbox' then 
      If ctl.Value = True Then     'if the control is marked as 'true' i.e. checked, then 
       ReDim Preserve stArray(0 To cnt)  'Reset the array dimension on each iteration of loop 
       stArray(cnt) = ctl.Caption    'Add value in value of checkbox caption to Array 
       cnt = cnt + 1       'Advance the counter to next array item 
      End If 
     End If 
    Next 

    Unload StratFill         'unload and close stratfill form 


    msg = "The following strategies will be priced:" & vbNewLine & vbNewLine 
    For i = LBound(stArray) To UBound(stArray)   'loops through all values of array 
      msg = msg & stArray(i) & vbCR    'strings together displayed txt 
    Next i 

     If MsgBox(msg, vbYesNo, "Confirm Strategies") = vbYes Then 
                    'if yes is clicked 
      Call RunPricing           '"RunPricing" will run 
     Else              'if no is clicked 
      StratFill.Show           'then the strategy selector box will display again 
     End If 

End Subの

答えて

0

これを試してみてください:

For i = 1 To UBound(stArray)      'loops through all values of array 

    Range("$D2:" & Range("D" & Rows.Count).End(xlUp).Address).Select 

    Selection.Find(What:=stArray(i), After:=ActiveCell, LookIn:=xlFormulas, _ 
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
    MatchCase:=False, SearchFormat:=False).Offset(0, 2).Select 

    msg = msg & stArray(i) & ActiveCell.Value & vbCR    'strings together displayed txt 
Next i 
+0

よりもむしろメッセージでそれを表示し、一致することが分かっているそれぞれに対して場合、プロセスを開始マークする方法があります配列の値は? – EmsBish

+0

@ emsbishあなたの元の質問にはあなたが持っている: 'msg = stArray(i)&vbCR 'strings together txt'あなたはrefで見つかった値にプロセスを実行できます。 ActiveCell.Valueまたは.Range。単に 'msg = msg'文を置き換えてください。 –

関連する問題