Code near completion, runtime error

Status
Not open for further replies.

bubububub

New Member
Joined
Jul 2, 2010
Messages
18
Hello,

I have a large column of UPC numbers I wish to identify. This code is designed to enter a search for UPCs at http://www.upcdatabase.com/itemform.asp. Then it copies the url of the search results page and pastes it in Excel 2007 next to its matching UPC. The end result should be a column of UPC numbers and a column of urls.

But every time I run code, I receive the error:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>

<TABLE class=MsoNormalTable style="WIDTH: 100%; mso-padding-alt: 4.5pt 4.5pt 4.5pt 4.5pt; mso-cellspacing: 0in; mso-yfti-tbllook: 1184" cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"><TD style="BORDER-RIGHT: #ece9d8 1pt inset; PADDING-RIGHT: 4.5pt; BORDER-TOP: #ece9d8 1pt inset; PADDING-LEFT: 4.5pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4.5pt; BORDER-LEFT: #ece9d8 1pt inset; PADDING-TOP: 4.5pt; BORDER-BOTTOM: #ece9d8 1pt inset"></TD></TR><TR style="mso-yfti-irow: 1; mso-yfti-lastrow: yes"><TD style="BORDER-RIGHT: #ece9d8 1pt inset; PADDING-RIGHT: 4.5pt; BORDER-TOP: #ece9d8 1pt inset; PADDING-LEFT: 4.5pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4.5pt; BORDER-LEFT: #ece9d8 1pt inset; PADDING-TOP: 4.5pt; BORDER-BOTTOM: #ece9d8 1pt inset">Run-time error '91':
Object variable or With block variable not set <o:p></o:p>

</TD></TR></TBODY></TABLE>[/Quote]

When I choose the debug option, this line is highlighted:
<o:p></o:p>
<TABLE class=MsoNormalTable style="WIDTH: 100%; mso-padding-alt: 4.5pt 4.5pt 4.5pt 4.5pt; mso-cellspacing: 0in; mso-yfti-tbllook: 1184" cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><TD style="BORDER-RIGHT: #ece9d8 1pt inset; PADDING-RIGHT: 4.5pt; BORDER-TOP: #ece9d8 1pt inset; PADDING-LEFT: 4.5pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4.5pt; BORDER-LEFT: #ece9d8 1pt inset; PADDING-TOP: 4.5pt; BORDER-BOTTOM: #ece9d8 1pt inset">doc.all("upc").Value = rngUPC.Text <o:p></o:p>
</TD></TR></TBODY></TABLE>


Any ideas to fix my broken code?

<o:p></o:p>

Please note: This code appears to work if the column has only 1 number. When applied to a column with many numbers, however, the error occurs.<o:p></o:p>

Thanks for your help,

Bub
P.S. Thanks, Norie, for helping me thus far.<o:p></o:p>
Code:
<o:p></o:p>[/SIZE][/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Sub Test()<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim IE As Object<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim doc As Object<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim frm As Object<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim rngUPC As Range<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]    Set IE = CreateObject("InternetExplorer.Application")<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]    Set rngUPC = Range("A1")<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]    With IE<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]        While rngUPC.Value <> ""<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            .Navigate "[URL="http://www.upcdatabase.com/itemform.asp"][COLOR=blue]http://www.upcdatabase.com/itemform.asp[/COLOR][/URL]"<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            Do Until .ReadyState = 4: DoEvents: Loop<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            Set doc = IE.Document<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            Set frm = doc.forms("upcform")<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            doc.all("upc").Value = rngUPC.Text<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            frm.submit<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            Do While IE.Busy: DoEvents: Loop<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            Do While IE.ReadyState <> 4: DoEvents: Loop<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            rngUPC.Offset(, 1) = doc.url<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]            Set rngUPC = rngUPC.Offset(1)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]        Wend<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]        .Quit<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]    End With<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]    Set IE = Nothing<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]End Sub<o:p></o:p>[/FONT][/COLOR]

[FONT=Calibri][SIZE=3]
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,362
Office Version
365
Platform
Windows
Bub

The code worked fine for me with multiple UPCs, the only thing I can think could possibly be causing is something to do with your browser or connectivity.

Can you post the data that is causing the error? I only tested using some random nos.

Though the error you describe doesn't sound as though it's caused by erroneous data.
 

bubububub

New Member
Joined
Jul 2, 2010
Messages
18
Norie,

Thanks for the help again.

Here are the first ten UPCs:
<TABLE style="WIDTH: 116pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=154 border=0><COLGROUP><COL style="WIDTH: 116pt; mso-width-source: userset; mso-width-alt: 5632" width=154><TBODY><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 116pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=154 height=20>000000000007</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000008</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000011</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000011</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000011</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000022</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000100</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000111</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000111</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>000000000111</TD></TR></TBODY></TABLE>

Bub
 
Status
Not open for further replies.

Forum statistics

Threads
1,082,099
Messages
5,363,129
Members
400,720
Latest member
Pettel

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top