2017-03-15 171 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, _ 

这些是错别字。搜索不是搜索!