Consulting

Results 1 to 3 of 3

Thread: Keeps overwriting my output

  1. #1
    VBAX Newbie
    Joined
    May 2021
    Posts
    1
    Location

    Keeps overwriting my output

    I am scraping price data from websites and although I can get the exact output I am looking for in the "Immediate" window, when I try to send it to a worksheet, it overwrites the cells with earlier data output with the last output.
    Please help!!

    Option Explicit
    Private cd As Selenium.ChromeDriver

    Sub WeeklyPrices()

    ' Open Chrome

    Dim cd As Selenium.ChromeDriver
    Dim RowNum As Integer, ColNum As Integer
    Set cd = New Selenium.ChromeDriver

    Dim Count As Integer
    For Count = 1 To 2

    Dim Value As String
    Dim names As Range
    Set names = Range("c1:c2")
    Dim cell As Range
    For Each cell In names

    cd.AddArgument "--headless"

    cd.start
    cd.get cell.Value

    'Find Headers

    Dim H2Headers As Selenium.WebElements
    Dim H2Header As Selenium.WebElement

    Set H2Headers = cd.FindElementsByCss("h2:nth-of-type(4)")

    For Each H2Header In H2Headers

    'Debug.Print H2Header.Text

    RowNum = Count
    ColNum = 1
    Cells(RowNum, ColNum) = H2Header.Text

    Next H2Header

    ' Find Prices

    Dim OtdListItems As Selenium.WebElements
    Dim OtdListItem As Selenium.WebElement

    Set OtdListItems = cd.FindElementsByCss("ul:nth-of-type(4)")

    For Each OtdListItem In OtdListItems

    'Debug.Print OtdListItem.Text

    RowNum = Count
    ColNum = 2
    Cells(RowNum, ColNum) = OtdListItem.Text

    Next OtdListItem

    Next cell

    Next Count

    cd.Quit

    End Sub
    Attached Files Attached Files

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    Please be aware this request has been posted on at least TWO OTHER forums. All postings fail to have utilized the code formatting tool located in the REPLY MENU bar.

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    If you would indent your code properly, you would immediately see the problem.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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