2017-02-20 11 views
0

こんにちは私はVBAコードで式を実装したいと思います。列内のすべての値が同じかどうかをチェックする必要があります。VBA式が正しく動作しない

Dim intBB2 As Integer 
Dim LastRow As Long 
Dim ISINcheck As String 

ISINcheck = WorksheetFunction.CountIf(ActiveWorkbook.Sheets(1).Range(Cells(2, intBB2), Cells(LastRow, intBB2)), _ 
ActiveWorkbook.Sheets(1).Range(Cells(2, intBB2))) _ 
= WorksheetFunction.CountA(ActiveWorkbook.Sheets(1).Range(Cells(2, intBB2), Cells(LastRow, intBB2))) 

変数intBB2LastRow式が計算のためにとるべき最後の行と列を見つける前コードからのものです。

範囲参照を範囲のアドレス(たとえばI2:I120)に置き換えた場合、範囲参照は機能します。しかし、そのままでは、アプリケーション定義またはオブジェクト定義エラーが発生します。

答えて

0

はそれをこのよう

intValueToFind = Cells(2, intBB2).Value 

For i = 2 To LastRow 
    If Not Cells(i, intBB2).Value = intValueToFind Then 
     ISINcheck = i 
    End If 
Next i 


If ISINcheck = "" Then 
    controlISIN = "N" 
Else 
    controlISIN = "Y" 
End If 

を解決ワークブック/ワークシートで、すべての範囲を修飾する必要がありますが、

+0

は、あなたが私の答えを試してみました動作しますか? – SJR

+0

はい、私は同じ間違いを受けました – tombata

+0

あなたは言ったでしょう。これらの変数に実際に値を割り当てましたか? – SJR

0

これを試してください。あなたはおそらくない最もエレガントな

With ActiveWorkbook.Sheets(1) 
     ISINcheck = WorksheetFunction.CountIf(.Range(.Cells(2, intBB2), .Cells(LastRow, intBB2)), _ 
      .Range(.Cells(2, intBB2))) _ 
      = WorksheetFunction.CountA(.Range(.Cells(2, intBB2), .Cells(LastRow, intBB2))) 
End With 
関連する問題