Move to the next blank cell

klatlap

Well-known Member
Joined
Sep 1, 2004
Messages
597
I know this is a simple one but i can't get the correct syntax, this macro prints URLs from table from a webpage, the problem is each new table starts in Row 2, what i need is for the first table to start in Row 2 but an new tables should start at the end of the last table printed.

I have used this in the past but can't make it work in this instance.

Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = Sheets("Sheet2").Range("A1").Value

Code:
Sub ProcessHTMLPage(HTMLPage As MSHTML.HTMLDocument)

    Dim HTMLTable As MSHTML.IHTMLElement
    Dim HTMLTables As IHTMLElementCollection
    Dim HTMLRow As MSHTML.IHTMLElement
    Dim HTMLCell As MSHTML.IHTMLElement
    Dim RowNum As Long, ColNum As Integer
    Dim i As Integer
    
 
    Set HTMLTables = HTMLPage.getElementsByTagName("Table")
    For Each HTMLTable In HTMLTables
      
            
        
        RowNum = 2
       
        For Each HTMLRow In HTMLTable.getElementsByTagName("tr")
            
            ColNum = 1
            For Each HTMLCell In HTMLRow.getElementsByTagName("a")
                Cells(RowNum, ColNum) = vbTab & HTMLCell.getAttribute("href")
                ColNum = ColNum + 1
            Next HTMLCell
            
            RowNum = RowNum + 1
            
        Next HTMLRow
      
       
       Next HTMLTable
 End Sub
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

klatlap

Well-known Member
Joined
Sep 1, 2004
Messages
597
gees, all i had to do was change RowNum = 2 to RowNum = RowNum +1
 

Watch MrExcel Video

Forum statistics

Threads
1,109,533
Messages
5,529,406
Members
409,871
Latest member
i1patrick
Top