2017-03-15 16 views
1

私は、特定の基準を見つけるために(ユーザーが入力される)セルの列を検索するようVBAを取得しようとしています。 (WorksheetFunction.CountIfsに苦労した後、私はこのコードに落ち着いてきましたが、この時点まで、動作するように見えた:VBA:名前付き引数が複数見つからない.Finds

Sub CalendarColor() 

Call VarDef 

Dim SearchEmpList As Range 
Dim SearchSDate As Range 
Dim SearchEDate As Range 
Dim SearchLType As Range 
Dim SearchPType As Range 

If EmpName <> "" Then 
    With Worksheets(2).Range("B:B") 'Search all of Employee Name list entries 
     Set SearchEmpList = .Find(What:=EmpName, _ 
            After:=.Cells(.Cells.Count), _ 
            LookIn:=xlValues, _ 
            LookAt:=xlWhole, _ 
            SearchOrder:=xlByRows, _ 
            SearchDirection:=xlNext, _ 
            MatchCase:=False) 
    End With 

だから、最初の列と特定されなければなら最初の変数です。関連の開始日に移動するには、私はこのコードを追加:私の目には

With Worksheets(2).Range("C:C") 'Search all of Start Date list entries 
     Set SearchSDate = .Find(What:=ActiveCell.Value, _ 
           After:=.Cells(.Cells.Count), _ 
           LookIn:=xlValues, _ 
           LookAt:=xlWhole, _ 
           SeachOrder:=xlByRows, _ 
           SeachDirection:=xlNext, _ 
           MatchCase:=False) 
    End With 

を、これはまったく同じですが、私は「実行時エラー 『448』を取得しています:名前付き引数が見つかりません。 "ステップインを使用してデバッグするとき

ActiveCell.Valueですか?あれば、ほかに何が使えますか?彼のスクリプトはループスクリプトで使用されます。ループスクリプトは各反復ごとに1つずつオフセットされます。つまり、ActiveCellが動作する場合、ActiveCellはもっともらしいようです。

ループスクリプトは次のようになります。

Sub ColorLoop() 

Dim EndNumberA As Integer '31 day months 
Dim EndNumberB As Integer '30 day months 
Dim EndnumberC As Integer '28 day months 
Dim EndNumberD As Integer '29 day months 
Dim i As Integer 

EndNumberA = 31 
EndNumberB = 30 
EndnumberC = 28 
EndNumberD = 29 

'Offset commands need to be tweaked each year to ensure the ActiveCell lands on the first day of the next month 

'January 31d 
For i = 1 To EndNumberA 
    Call CalendarColor 
    ActiveCell.Offset(, 1).Select 
Next i 

'Set ActiveCell to Feb1 
ActiveCell.Offset(1, -28).Select 

'February 28d (Use EndNumberD if leap year) 
For i = 1 To EndnumberC 
    'Call CalendarColor 
    ActiveCell.Offset(, 1).Select 
Next i 

'Set ActiveCell to Mar1 
ActiveCell.Offset(1, -28).Select 

私はVBA(と私の最初のポストここを)学習に約2週間をしていますので、何でもあなたが持っていることは歓迎の情報です。

+4

'SeachOrder' <>' SearchOrder'、 'SeachDirection' <>' SearchDirection'です。 – GSerg

+0

これはどういう意味か分かりません...?ごめんなさい! – Exulansis

+0

あなたは見つからない** r ** seachOrder – cyboashu

答えて

0
SeachOrder:=xlByRows, _ 
SeachDirection:=xlNext, _ 

これらはタイプミスです。検索しないでください!

関連する問題