2012-07-09 4 views
-1

함수의 결과를 찾으려면 VB 2010에서 .Find을 사용하려고합니다. 내가 xlValuesxlFormulas 모두를 시도Excel. 함수의 결과 찾기 2010

firstFind = xlWorkSheet.Range("E10", "CM10").Find(searchDate, ,  Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False) 

:

내 코드입니다.

엑셀 기능은 매우 간단하고 다음과 같습니다

=G9+7 

결과는 날짜, 19 7 월이고, 그게 내가 검색 할 수있는입니다. 첫째

BR 세바스찬

답변

0

내가 .find

Const FOUND As Integer = 1, NOT_FOUND = 0 
Dim worksheetNr As Integer = 0, columnNr As Integer, dateFound As Integer = NOT_FOUND 

While worksheetNr < xlWorkBook.Worksheets.Count And dateFound = NOT_FOUND 

    Try 
     xlWorkSheet = xlWorkBook.Worksheets(worksheetNr) 
     xlWorkSheet.Activate() 
     columnNr = 7 
     While dateFound = NOT_FOUND And (columnNr < 100) 
      If (xlWorkSheet.Cells(10, columnNr).Value.Equals(searchDate)) Then 
       dateFound = FOUND 
      Else 
       columnNr += 1 
      End If 

     End While 

    Catch ex As Exception 
     Console.Write("") 
    End Try 

End While 
를 사용하지 않고 문제를 해결하는 방법은 다음과 같습니다 당신과 함께 그 라인을 대체 할 수 있습니다
0

우선. Excel은 날짜를 정수로 간주하므로 19-7 월은 실제로 숫자입니다 (셀을 일반 = G9 + 7로 설정). 예를 들어 2012 년 7 월 19 일 = 41109입니다. 희망이 있습니다.

1

찾기 기능을 사용하는 대신 열을 반복 할 수 없습니까? 이 같은 뭔가 향후 사용자 정의하는 것이 더 효율적 또는 쉽게 할 수있다 :

Sub Test() 

    Dim iColumnSearch As Long 
    Dim dtSearchDate As Date 
    Dim rngFoundInCell As Range 

    dtSearchDate = "7/16/2012" 

    '- loop through columns E to CM (Column #'s 5 to 91) 
    For iColumnSearch = 5 To 91 
     If Cells(10, iColumnSearch).Value = dtSearchDate Then 

      Set rngFoundInCell = Cells(10, iColumnSearch) 
      Exit For 
     End If 
    Next iColumnSearch 

    If Not rngFoundInCell Is Nothing Then '-if was found 
     MsgBox "Found in cell: " & rngFoundInCell.Parent.Name & "!" & rngFoundInCell.Address(External:=False) 
    End If 


    Set rngFoundInCell = Nothing 

End Sub 

업데이트 : 내가하지 않았기 때문에 위의 코드는 특별히 날짜 '2012/07/16'을 검색 한

주 검색 문자열의 위치를 ​​확인하십시오.

다음
dtSearchDate = Range("G9").value + 7