我的宏在所有打開的工作簿中搜索活動單元格值(例如98%)。但是,它只能找到值0.98而不是其他單元格中的值98%。爲什麼?VBA查找函數忽略百分比 - >只發現小數
這裏是我的宏:
Sub FindIt2()
Dim wSheet As Worksheet
Dim wBook As Workbook
Dim rFound As Range
Dim firstAddress As String
lookfor = Selection.Value
On Error Resume Next
For Each wBook In Application.Workbooks
For Each wSheet In wBook.Worksheets
Set rFound = wSheet.Cells.Find(What:=lookfor, After:=wSheet.Cells(1, 1), _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not rFound Is Nothing Then
firstAddress = rFound.Address
Do
Application.Goto rFound, True
MsgBox "The Search String has been found these locations: "
Set rFound = wSheet.Cells.FindNext(rFound)
Loop While Not rFound Is Nothing And rFound.Address <> firstAddress
End If
Next wSheet
Next wBook
On Error GoTo 0
任何人有一個想法如何解決這個問題?謝謝!
編輯:我希望它找到這兩個98%和0.98
你永遠不會定義你的搜索值所在的變量。因此,如果我沒有記錯,它將按定義成爲一個整數。 – Luuklag
是的,你沒錯,我沒有定義它。但是,它似乎並沒有成爲一個整數,因爲我發現0.98。 什麼是適當的定義?我使用宏的許多不同類型的值.. – Lennart
我認爲最好將工作表中的值轉換爲所有分數或所有百分比。否則,你最終會檢查兩個變量。 – Luuklag