2012-11-23 4 views
2

내가 코드 오류 424 개체가VBA의 찾기 기능은

lr = Range("O:O").Cells(Rows.Count, 1).End(xlUp).Row 

For y = 0 To UBound(myVariable) 
    a = myVariable(y) 
    Range("O:O").Select 
    Set objXL = GetObject(, "Excel.Application") 
    Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _ 
     LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
     MatchCase:=False, SearchFormat:=False).Activate 
    If z = "True" Then 
     ActiveCell.Delete shift:=xlUp 
    End If 
    MsgBox z.Value 
Next 
+0

좋은 읽기 http://www.siddharthrout.com/2011/07/14/find-and-findnext-in-excel-vba/ –

답변

1

찾기가 범위 객체를 검색 요구 받고이 필요합니다. 그래서 당신은 다음 중 하나

A)) 발견 된 범위

Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _ 
    LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
    MatchCase:=False, SearchFormat:=False).Activate 

또는

B를 활성화 두 가지를 동시에 사용하여 변수

Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _ 
    LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
    MatchCase:=False, SearchFormat:=False).Activate  'No .Activate in here ' 

에 발견 된 범위를 지정 오류가 발생합니다.

참고 :

주의 하시고. .Find이 일치하는 항목을 찾지 못하면 Nothing을 검색합니다. 이 경우 .Activate은 오류 메시지를 표시합니다. 그래서 여기에 몇 가지 오류 처리를 사용하십시오.