我正在运行这个Sub,它正在工作,但是被抓取的数据正在写入第二行,并且每个实例都覆盖了最后一个。我看不到我的脚本错在哪里。请帮助我了解:Excel VBA - 为什么数据覆盖同一行?
Option Explicit
Sub test()
Dim ele As Object
Dim objIE As Object
Dim RowCount As Double
Dim sht As Worksheet
Dim myjobtype As String
Dim myzip As String
Dim what
Dim zipcode
Set sht = Sheets("Sheet1")
RowCount = 1
sht.Range("A" & RowCount) = "Title"
sht.Range("B" & RowCount) = "Company"
sht.Range("C" & RowCount) = "Location"
sht.Range("D" & RowCount) = "Description"
Set objIE = CreateObject("InternetExplorer.Application")
myjobtype = InputBox("Enter type of job eg. sales, administration")
myzip = InputBox("Enter zipcode of area where you wish to work")
With objIE
.Visible = True
.navigate "http://www.jobs.com/"
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
Set what = .document.getElementsByName("q")
what.Item(0).Value = myjobtype
Set zipcode = .document.getElementsByName("where")
zipcode.Item(0).Value = myzip
.document.forms(0).submit
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
For Each ele In .document.all
Select Case ele.classname
Case "cardview"
RowCount = RowCount + 1
Case "jobTitle"
sht.Range("A" & RowCount) = ele.innertext
Case "company"
sht.Range("B" & RowCount) = ele.innertext
Case "location"
sht.Range("C" & RowCount) = ele.innertext
Case "preview"
sht.Range("D" & RowCount) = ele.innertext
End Select
Next ele
End With
Set objIE = Nothing
End Sub
感谢您的建议,不幸的是,在Select Case之外移动RowCount并没有帮助。 然后,我将您的建议替换为选择语句,但它将所有内容都放入D列。 应该如何增加行的增量? – Python