+ Reply to Thread
Results 1 to 4 of 4

Change coding to run across multiple rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    758

    Change coding to run across multiple rows

    Hello,

    I currently have the following coding for a set of data on an excel spreadsheet:

    Sub DemoMutual2()
    Dim URL As String
    Dim ieDoc As Object, dObj As Object
    Dim cel As Range
    
        URL = Range("G2").Value
        With CreateObject("InternetExplorer.Application")
            .Visible = False
            .Navigate URL
    
            Do Until .ReadyState = 4: DoEvents: Loop
    
            Set ieDoc = .Document
            Set dObj = ieDoc.getElementsByClassName("_50f3")
            [K2].Value = Split(ieDoc.getElementsByClassName("_50f3")(0).innerText, " ")(0)
            For i = 0 To dObj.Length - 1
                If InStr(1, dObj(i).getElementsByTagName("a")(0).innerText, "since") Then
                    [M2].Value = Trim(Split(dObj(i).getElementsByTagName("a")(0).innerText, "since")(1))
                End If
            Next
            .Quit
        End With
        Set ieDoc = Nothing
        Set dObj = Nothing
    End Sub
    At present this only works on one row, based on the URL in cell G2. What I want this code to do is run for all of the URLs in column G (G2,G3,G4 etc) and return the required results in the cells specified in the code (K2, K3, K4 etc and M2, M3, M4 etc).

    At present this works perfectly for the one row, but I am struggling to change it so I can do it for multiple rows.

    Any help is much appreciated.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,228

    Re: Change coding to run across multiple rows

    Hi Chris,

    See if this works. The trick is to change the range to cells and use a ForNext Loop.

    Sub DemoMutual2()
    Dim URL As String
    Dim ieDoc As Object, dObj As Object
    Dim cel As Range
    Dim LastRow As Double
    Dim RowCtr As Double
    
    LastRow = Cells(Rows.Count).End(xlUp).Row
    
    For RowCtr = 2 To LastRow
        URL = Cells(RowCtr, "G").Value
        With CreateObject("InternetExplorer.Application")
            .Visible = False
            .Navigate URL
    
            Do Until .ReadyState = 4: DoEvents: Loop
    
            Set ieDoc = .Document
            Set dObj = ieDoc.getElementsByClassName("_50f3")
            Cells(RowCtr, "M").Value = Split(ieDoc.getElementsByClassName("_50f3")(0).innerText, " ")(0)
            For i = 0 To dObj.Length - 1
                If InStr(1, dObj(i).getElementsByTagName("a")(0).innerText, "since") Then
                    [M2].Value = Trim(Split(dObj(i).getElementsByTagName("a")(0).innerText, "since")(1))
                End If
            Next
            .Quit
        End With
        Set ieDoc = Nothing
        Set dObj = Nothing
    Next RowCtr
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    758

    Re: Change coding to run across multiple rows

    Hi Marvin,

    Many thanks for your response.

    I am afraid that didnt work. I have noticed there is nothing in the coding regarding column K and that part of the scrape into that cell...

  4. #4
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    758

    Re: Change coding to run across multiple rows

    Still struggling with the code on this one. Anyone able to help?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Change Event, Move multiple rows based on drop down selection for multiple criteria
    By Webbers in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-02-2017, 11:51 AM
  2. [SOLVED] How to change coding in Macro for Pivot
    By sudharshan86 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2014, 10:19 AM
  3. Replies: 2
    Last Post: 11-01-2013, 03:23 AM
  4. [SOLVED] Rows over-typing previous rows of data when automatically being moved using vba coding
    By Kaz09 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2013, 01:41 PM
  5. [SOLVED] Multiple issues - Multiple IF staements with multiple answers, or other coding.
    By inzanesrt4 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-12-2013, 08:53 PM
  6. [SOLVED] Change multiple rows to multiple columns with one row
    By lhellmer in forum Excel General
    Replies: 6
    Last Post: 11-15-2012, 07:32 PM
  7. Change multiple columns into multiple rows
    By JimmyA in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2008, 08:51 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1