2016-09-11 6 views
0

Ich plane Daten aus einer Tabelle im Internet zu extrahieren. Der folgende Code stammt hauptsächlich aus der integrierten Webauslagerungsfunktion in Excel.VBA: Drucken auf der letzten Reihe von Excel

Ich möchte die letzte Zeile mit Daten finden und auf die erste leere Zeile drucken.

Sub Sub1() 

ActiveSheet.Cells.Clear 

Dim lastRow As Long 
Dim i As Integer 

For i = 1 To 2 

With ActiveSheet.QueryTables.Add(Connection:= _ 
    "URL;http://www.aastocks.com/tc/stocks/quote/symbolsearch.aspx?page=" & i & " &order=symbol&seq=asc", Destination _ 
    :=Range("A,lastRow")) '???? I got an error here, what I want is to detect the last row and print on the first blank row.??? 
    '.CommandType = 0 
    .Name = "symbolsearch_1" 
    .FieldNames = True 
    .RowNumbers = False 
    .FillAdjacentFormulas = False 
    .PreserveFormatting = True 
    .RefreshOnFileOpen = False 
    .BackgroundQuery = True 
    .RefreshStyle = xlInsertDeleteCells 
    .SavePassword = False 
    .SaveData = True 
    .AdjustColumnWidth = True 
    .RefreshPeriod = 0 
    .WebSelectionType = xlSpecifiedTables 
    .WebFormatting = xlWebFormattingNone 
    .WebTables = "10" 
    .WebPreFormattedTextToColumns = True 
    .WebConsecutiveDelimitersAsOne = True 
    .WebSingleBlockTextImport = False 
    .WebDisableDateRecognition = False 
    .WebDisableRedirections = False 
    .Refresh BackgroundQuery:=False 
End With 
lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1 

Debug.Print lastRow 
Next i 

End Sub 

Antwort

0

Dies scheint jetzt in Ordnung zu arbeiten. Sie waren in der Nähe, Sie sollten in der Lage sein, nach Bedarf zu bearbeiten.

Sub Sub1() 

ActiveSheet.Cells.Clear 

Dim lastRow As Long 
Dim i As Integer 
Dim sTicker As String 

'set the first row to write to 
lastRow = 2 

For i = 1 To 2 
sTicker = InputBox("Enter the code to search for") 
With ActiveSheet.QueryTables.Add(Connection:= _ 
    "URL;http://www.aastocks.com/tc/stocks/quote/symbolsearch.aspx?page=" & sTicker & " &order=symbol&seq=asc", Destination _ 
    :=Range("A" & lastRow)) 'uses the ticker value entered and fixed the destination part 
    '.CommandType = 0 
    .Name = "symbolsearch_1" 
    .FieldNames = True 
    .RowNumbers = False 
    .FillAdjacentFormulas = False 
    .PreserveFormatting = True 
    .RefreshOnFileOpen = False 
    .BackgroundQuery = True 
    .RefreshStyle = xlInsertDeleteCells 
    .SavePassword = False 
    .SaveData = True 
    .AdjustColumnWidth = True 
    .RefreshPeriod = 0 
    .WebSelectionType = xlSpecifiedTables 
    .WebFormatting = xlWebFormattingNone 
    .WebTables = "10" 
    .WebPreFormattedTextToColumns = True 
    .WebConsecutiveDelimitersAsOne = True 
    .WebSingleBlockTextImport = False 
    .WebDisableDateRecognition = False 
    .WebDisableRedirections = False 
    .Refresh BackgroundQuery:=False 
End With 
lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1 

Next i 

End Sub