Redim Lbound(更改范围) [英] Redim Lbound ( Changing Range )
问题描述
因此,我是vba的新手,我试图争取价格.宏是:
So I'm new to vba and i am try to get price. The macro is :
Sub GetPrice()
Dim objIE As InternetExplorer
Dim Prc1 As String
Set objIE = New InternetExplorer
Dim Search_Terms() As Variant
Dim CopiedData() As Variant
Dim y As Integer
objIE.Visible = False
Search_Terms = Application.Transpose(ActiveSheet.Range("A2:A50").Value)
ReDim CopiedData(LBound(Search_Terms) To UBound(Search_Terms))
y = 2
For a = LBound(Search_Terms) To UBound(Search_Terms)
objIE.navigate "https://Example.com/?loc=shop_search&app=578080_2&sort=lh&search_item=" & Search_Terms(a)
Do: DoEvents: Loop Until objIE.readyState = 4
Prc1 = objIE.document.getElementsByClassName("item-amount")(0).innerText
Sheets("Sheet1").Range("B" & y).Value = Prc1
objIE.navigate "http://Example2.com/market/search?appid=578080&q=" & Search_Terms(a)
Do: DoEvents: Loop Until objIE.readyState = 4
Prc1 = objIE.document.getElementsByClassName("market_table_value")(1).getElementsByTagName("span")(0).innerText
Sheets("Sheet1").Range("D" & y).Value = Prc1
Dim i As String
Dim k As String
i = "TL"
k = ""
Columns("D").Replace what:=i, replacement:=k, lookat:=xlPart, MatchCase:=False
y = y + 1
Next
ActiveSheet.Range(Cells(1, 2), Cells(UBound(CopiedData), 2)) = Application.Transpose(CopiedData)
objIE.Quit
End Sub
当我尝试机会时: Search_Terms = Application.Transpose(ActiveSheet.Range("A2:A121").Value)
至: Search_Terms = Application.Transpose(ActiveSheet.Range("A2:A50").Value)
When i try to chance:
Search_Terms = Application.Transpose(ActiveSheet.Range("A2:A121").Value)
to:
Search_Terms = Application.Transpose(ActiveSheet.Range("A2:A50").Value)
它进入A50并删除excel中的所有结果并停止.我应该怎么办 ?您可以解释和编写正确的代码吗?
its coming to A50 and deleting the all results in excel and stop. What should i do ? Can u explain and write correct codes ?
推荐答案
此代码行:
ActiveSheet.Range(Cells(1, 2), Cells(UBound(CopiedData), 2)) = Application.Transpose(CopiedData)
...最初旨在将CopiedData中的值放回工作表中.但是,您不再填充CopiedData了.您正在使用Prc1将值写回到工作表中.
... was originally designed to put the values from CopiedData back into the worksheet. However you are not populating CopiedData anymore; you are using Prc1 to write values back to the worksheet.
删除或注释"上面的代码行.
Delete or 'comment out' the above code line.
这篇关于Redim Lbound(更改范围)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!