作者:乔山办公网日期:
返回目录:excel表格制作
VBA不是万能的,也需要抄数据比对的逻辑,即对照表,才能写代码。袭
需要基础资料进行比对百,工号对应姓名,Vlookup进行匹配。
计算度相同工号,相同产品的出现次数,countifs计算符合姓名和产品号问相同的数量
按照要求的格式抓取对应答的数据
分析好久才弄出来的,经实测成功,望采纳...
Sub test()
Dim strUrl$, objHttp As Object, strRtn, arrRtn, i%, j%
strUrl = "http://f9.eastmoney.com/soft/gp13.php?code=00000202"
Set objHttp = CreateObject("msxml2.xmlhttp")
objHttp.Open "GET", strUrl, 0
objHttp.send
While objHttp.readystate <> 4
DoEvents
Wend
Cells.Clear '清除表格内容
Rows(2).NumberFormatLocal = "@" '第二行设置e79fa5e98193e59b9ee7ad94334为文本格式
'取 "<table" 之后的内容
strRtn = Split(objHttp.responsetext, "<table", -1, vbTextCompare)(1)
'以 "<tr>" 作为分隔符把数据分为行数组
strRtn = Split(strRtn, "<tr>", -1, vbTextCompare)
For i = 0 To UBound(strRtn) '行循环
'各个字段以 "<span>" 分隔
arrRtn = Split(strRtn(i), "<span>", -1, vbTextCompare)
For j = 1 To UBound(arrRtn) '列循环
'取"</span>"之前的内容,并且把" "替换为空,然后输出到表格里
Cells(i + 1, j + 1) = Replace(Split(arrRtn(j), "</span>", -1, vbTextCompare)(0) _
, " ", "", 1, -1, vbTextCompare)
Next j
Next i
Set objHttp = Nothing
MsgBox "done..."
End Sub
供参来考
Sub test()
Dim myQuery
With ActiveSheet
.Cells.Delete
.[a1] = "Conneting, Please Wait..."
Set myQuery = ActiveSheet.QueryTables _
.Add(Connection:="URL;", _
Destination:=.Cells(1, 1))
End With
With myQuery
.Refresh
End With
补充:grhsc你不是知道读取全部网页的程序源吗?那里可以先把整个网页以表格的方式读百取到excel中,建立一度个临时sheet,然后删除掉多知余的数道据,或者在excel中在读取需要的数据不就行了?