1

ループでそのすぐ下のセルのティッカーを照会し、列内のすべてのティッカーのデータを取得するまでループします。

概要:

列 A のティッカー シンボルのデータを取得しようとしています。これは私が使用しているコードです。

Sub URL_Static_Query()


''Pull Data from Profile

With Sheet2.QueryTables.Add(Connection:= _
      "URL;http://finance.yahoo.com/q/pm?s=" & Sheet1.Range("A2").Value & "+Performance", _
         Destination:=Sheet2.Range("A1"))
 .BackgroundQuery = True
 .TablesOnlyFromHTML = True
 .Refresh BackgroundQuery:=False
 .SaveData = True

 End With

''Pull Data from Performance
 With Sheet3.QueryTables.Add(Connection:= _
      "URL;http://finance.yahoo.com/q/pr?s=" & Sheet1.Range("A2").Value & "+Profile", _
         Destination:=Sheet3.Range("A1"))

.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

'Grab and Paste 3-month
Sheets("Sheet2").Select
Range("A1").Select

Cells.Find(What:="3-month", After:=ActiveCell, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate

ActiveCell.Offset(0, 1).Select
Selection.Copy

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste

'Grab and Paste 1-Year
Sheets("Sheet2").Select
Range("A1").Select

Cells.Find(What:="1-Year", After:=ActiveCell, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate

ActiveCell.Offset(0, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 2).Select

Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True

 Sheets("Sheet3").Select
 Range("A1").Select

 Cells.Find(What:="Prospectus Net Expense Ratio:", After:=ActiveCell, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate

ActiveCell.Offset(0, 1).Select
Selection.Copy
Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste

Sheet2.Cells.Clear
Sheet3.Cells.Clear

End Sub
4

1 に答える 1

1

このコードを、列内の各セルを 1 つずつ下るループでラップできます。

たとえば、列 A を使用している場合、

Dim row_counter As Long, last_row As Long
row_counter = 1
'last_row = whatever your last row is

Do While row_counter < last_row
  '... put looping code here
  row_counter = row_counter + 1
Loop
于 2013-09-04T19:51:11.943 に答える