2017-04-18 80 views
1

當使用宏搜索時,我無法搜索我知道在Excel表單中存在的單詞。我檢查了所有選項,但無法找到爲什麼會發生這種情況。 var2是1082591.html和1082592.html等等。當我在excel中找到Total時,它找不到它。由於通過宏搜索單詞時查找函數不起作用

Sub DataPull() 
Dim Website 
Application.DisplayAlerts = False 
var1 = 2 
Do Until Range("A" & var1) = "" 
var2 = Range("A" & var1).Value 
Hostteam = Range("C" & var1).Value 
Hosts = Hostteam & " innings" 
Visitorteam = Range("D" & var1).Value 
Visitors = Visitorteam & " innings" 
Website = "http://www.espncricinfo.com/indian-premier-league-2017/engine/match/" & var2 
Set myIE = CreateObject("InternetExplorer.Application") 
myIE.Navigate Website 
myIE.Visible = True 
Application.Wait Now + TimeSerial(0, 0, 5) 
SendKeys "^a" 
Application.Wait Now + TimeSerial(0, 0, 1) 
SendKeys "^c" 
Application.Wait Now + TimeSerial(0, 0, 1) 
Workbooks.Add 
ActiveWorkbook.SaveAs Filename:=var2 
ActiveSheet.Paste 
Application.Wait Now + TimeSerial(0, 0, 10) 
Cells.Find(What:=Hosts, After:=ActiveCell, LookIn:= _ 
     xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
     xlNext, MatchCase:=False, SearchFormat:=False).Activate 
Cells.Find(What:="Total", After:=ActiveCell, LookIn:= _ 
     xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
     xlNext, MatchCase:=False, SearchFormat:=False).Activate 
ActiveCell.Offset(0, 2).Copy 
ThisWorkbook.Activate 
Range("J" & var1).Select 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
     :=False, Transpose:=False 
Workbooks(var2).Activate 
Cells.Find(What:=Visitors, After:=ActiveCell, LookIn:= _ 
     xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
     xlNext, MatchCase:=False, SearchFormat:=False).Activate 
Cells.Find(What:="Total", After:=ActiveCell, LookIn:= _ 
     xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
     xlNext, MatchCase:=False, SearchFormat:=False).Activate 
ActiveCell.Offset(0, 2).Copy 
ThisWorkbook.Activate 
Range("L" & var1).Select 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
     :=False, Transpose:=False 
myIE.Quit 
Set myIE = Nothing 
Err.Clear 
Workbooks(var2).Activate 
ActiveWorkbook.Close 
ThisWorkbook.Activate 
Range("O" & var1).Value = "Done" 
var1 = var1 + 1 
Loop 
End Sub 
+2

我們將無法確定您的代碼無法正常工作的原因,除非您將問題粘貼到無法使用的代碼中。 – YowE3K

回答

0

寫搜索前這兩條線的「彙總」,看看你有什麼活動單元格,並在表:

debug.print activecell.address 
debug.print activecell.parent.name 
Cells.Find(What:="Total", After:=ActiveCell, LookIn:= _ 
     xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
     xlNext, MatchCase:=False, SearchFormat:=False).Activate 
ActiveCell.Offset(0, 2).Copy 

這可能是沒有找到它的理由。如果是這種情況,請考慮不要搜索After:ActiveCell,而是使用一個變量來設置它。

+0

謝謝,宏正在搜索前兩次迭代的數據,但之後沒有。我嘗試手動搜索以及然後發現似乎被禁用在此Excel表單。我無法弄清楚這個問題。 – Nishant