2017-03-15 27 views
1

我一直在試圖讓VBA搜索一列單元格(將被用戶填充)來查找特定條件。與WorksheetFunction.CountIfs掙扎之後(我已經看中了這個代碼,併到這一點,它似乎工作:VBA:命名的參數未找到,多個。找到

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嗎?如果是這樣,我還能使用什麼?T他的腳本將被用在循環腳本中,每次迭代都會偏移1,所以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 

我大約2星期到學習VBA(和我的第一篇文章在這裏),所以無論你是歡迎信息。

+4

'SeachOrder' <>'SearchOrder','SeachDirection' <>'SearchDirection'。 – GSerg

+0

我不確定這是什麼意思...?抱歉! – Exulansis

+0

你缺少** r **在seoOrder – cyboashu

回答

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

這些是錯別字。搜索不是搜索!