2013-07-26 4 views
0

범위 내에서 OR 함수를 삽입 할 수 있습니까? 나는이 기능이 있지만이 개 값범위 내에서 Or 함수 사용 VBA

당신이 내가 OR 문에 넣어 시도했지만 Excel이 나에게 화를 얻는다을 찾고 무엇을 제공 라인에서
With Worksheets("Term").Range("A:A") 

     Set rng = .Find(What:=Worksheets("Term and Discipline").Range("K7"), _ 
         After:=.Cells(.Cells.Count), _ 
         LookIn:=xlValues, _ 
         LookAt:=xlPart, _ 
         SearchOrder:=xlByRows, _ 
         SearchDirection:=xlNext, _ 
         MatchCase:=False) 
     Application.Goto rng, True 
End With 

중 하나를 찾기 위해 그것을하고 싶습니다 실행하려고 할 때

+1

[참조] (oracle)에 대한 [참조] (http://stackoverflow.com/questions/8042744/excel-vba-instr-condition-doesnt-work-with-2-or-more-conditions/8047021#8047021) 회로. – pnuts

답변

1

Range.Find 메서드는 Excel에서 Ctrl + F를 입력 할 때와 같은 창을 에뮬레이트합니다. 같은 창에서 동시에 2 개 이상의 값을 검색 할 수 없기 때문에 VBA를 통해 동시에 2 개 이상의 값을 검색 할 수 있다고 생각하지 않습니다. 불행히도 두 번이나 방법을 써야한다고 생각합니다.

내가 틀렸다면 어떻게하는지 알고 싶습니다. 그것은 매우 유용 할 것입니다. 그래서 제발 나를 잘못 증명해 주시기 바랍니다 :)

내 테스트에서 Range.Find 메서드는 배열 또는 두 개 이상의 셀 범위를 지원하지 않습니다. 그래서 그들은 빠져 있습니다.

또한 OR을 사용하면 OR이 TRUE/FALSE를 확인하고 TRUE/FALSE를 반환하기 때문에 올바르게 작동하지 않습니다.

2

가장 가까운 것은 동등하게 (효과적으로) 검색을 수행하고 MIN()을 사용하여 발견 된 첫 번째 셀을 선택하는 것입니다.

rngFoo 또는 rngBar 중 하나만 Nothing 인 경우 추가 체크가 필요합니다.

Sub FindingNemor() 
    Dim rngFoo As Range 
    Dim rngBar As Range 

    Set rngFoo = Cells.Find(What:="foo", After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _ 
     xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ 
     , SearchFormat:=False) 
    Set rngBar = Cells.Find(What:="bar", After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _ 
     xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ 
     , SearchFormat:=False) 

    If Not rngFoo Is Nothing And Not rngBar Is Nothing Then 
     Range("A1").Cells(Application.Min(rngFoo.Row, rngBar.Row)).Select 
    ElseIf rngFoo Is Nothing Then 
     If rngBar Is Nothing Then 
      MsgBox "Neither found." 
     Else 
      Range("A1").Cells(rngBar.Row).Select 
     End If 
    Else 
     Range("A1").Cells(rngFoo.Row).Select 
    End If 
End Sub 
0

당신은 당신의 범위에있는 모든 세포를 통해 루프에 필요 Or.

와 함께 If 문에서 Like 기능 또는 InStr를 사용 Nothing -ness 점검

추가 그것을 조금 지저분하게

관련 문제