VBA help editing existing code for web lookup

nialcooper

New Member
Joined
Mar 14, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi I am trying to populate an excel sheet with data using the barcode from a book, i have found a code that works as a button assigned macro and for all purposes it works well. the problem i have with it is that when it runs it performs a search in google books for every line in the sheet which dramatically slows it down when you get to around 40+ lines, i don't know enough about coding to edit tis code so that it will only perform the search on rows that have not already been populated. here is the code

VBA Code:
Public Sub isbnExample()
    Dim dset As cDataSet
    ' get ISBN book data
    ' load to a dataset
    Set dset = New cDataSet
    With dset
        ' create a dataset from the isbn worksheet
        .populateData wholeSheet("isbn"), , "isbn", , , , True

        If .where Is Nothing Then
            MsgBox ("No data to process")
        Else
            'check we have the isbn column present
            If .headingRow.validate(True, cISBNColumnHeading) Then
                ' if there were any updates then commit them
                If processISBN(dset) > 0 Then
                    .bigCommit
                End If
                
            End If
        End If
    End With
    Set dset = Nothing

End Sub
Private Function processISBN(ds As cDataSet) As Long

    Dim dset As cDataSet, cb As cBrowser, dr As cDataRow
    Dim jo As cJobject, job As cJobject, n As Long
    Dim sWire As String
    ' gets a book details by isbn number
    Set cb = New cBrowser
    Set jo = New cJobject
    n = 0
    For Each dr In ds.rows
        With dr.cell(cISBNColumnHeading)
            sWire = cb.httpGET(cISBNGoogleBooks & .toString)
            Set job = jo.deSerialize(sWire)
            If Not job.isValid Then
                MsgBox ("Badly formed jSon returned for ISBN" & .toString & "-" _
                    & sWire)
            
            ElseIf Not job.childExists("error") Is Nothing Then
                MsgBox ("Google books refuses to co-operate for ISBN " _
                        & .toString _
                        & "-" & job.child("error").serialize)
                
            ElseIf job.childExists("Items") Is Nothing _
                Or job.childExists("totalItems") Is Nothing Then
                MsgBox ("Could find no data for ISBN " _
                        & .toString _
                        & "-" & job.serialize)
            
            ElseIf job.child("totalItems").value <> 1 Then
                MsgBox ("Multiple entries for " _
                        & .toString _
                        & "-" & job.child("totalItems").serialize)
            
            Else
                ' fill in this row
                n = n + rowProcess(dr, job.child("Items"))
            End If
        End With
    Next dr
    processISBN = n
End Function
Private Function rowProcess(dr As cDataRow, job As cJobject) As Long
    Dim hc As cCell, n As Long, jo As cJobject, jom As cJobject
    n = 0
    For Each hc In dr.parent.headings
        ' any headings that are present in the dataset
        ' and also in the returned json get populated
        With hc
            If .toString <> cISBNColumnHeading Then
                Set jo = job.find(.toString)
                If Not jo Is Nothing Then
                    With dr.cell(.column)
                        ' if multiple then include the array separated by commas
                        If jo.isArrayRoot Then
                            .value = vbNullString
                            If jo.hasChildren Then
                                For Each jom In jo.children
                                    If .toString <> vbNullString Then
                                        .value = .value & ","
                                    End If
                                    .value = .value & jom.toString
                                Next jom
                            End If
                        Else
                            .value = jo.value
                        End If
                    End With
                    n = n + 1
                End If
            End If
        End With
    Next hc
    rowProcess = n
End Function

here is a snip of the work sheet, i would post the worksheet but it is a mess of code that dosn't apply to the sheet i am working with. currently whenever i press the button top right it will perform a search on all rows, iwould like for it to search on lines that do not have data in column B.is this possible? Thanks in advance for looking
1676160171343.png
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
or would be even better if the code could run when the barcode data is input in to column A automatically for the last changed row, if that makes sense
 
Upvote 0
Could someone point me in the right direction to edit this please? I have a rough idea of how to edit but can not figure out where to edit
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top