type missmatch error

JudahRaion

New Member
Joined
Oct 13, 2011
Messages
20
Hi, someone know why when after 50 times doing this loop vba give me back an error "type missmatch"?

I can't figure it out.

Thank you a lot guys.

Code:
Sub observacoes()

the_start:


Dim rng As Range


clientes = Range("A10000").End(xlUp).Row
For k = 2 To clientes
   
    'Set ie = New InternetExplorerMedium
    Set ie = CreateObject("InternetExplorer.Application")
    ncliente = Range("A" & k)
    ie.navigate ("URL" & ncliente)
    ie.Visible = False
    
    Do
    DoEvents
            If Err.Number <> 0 Then
                ie.Quit
                Set ie = Nothing
                GoTo the_start:
            End If
    
    Loop Until ie.readyState = 4
    
    allHTML = ie.document.body.innerHTML
    
    ''observação data
        If InStr(allHTML, "Responsável") > 0 Then
        leng = Len("Responsável")
        obsdt = Mid(allHTML, InStr(allHTML, "Responsável") + leng, Len(allHTML))
        leng = Len("conteudo")
        obsdt = Mid(obsdt, InStr(obsdt, "conteudo") + leng, Len(obsdt))
        leng = Len("<small><font")
        obsdt = Mid(obsdt, InStr(obsdt, "<small><font") + leng, Len(obsdt))
        leng = Len(">")
        obsdt = Mid(obsdt, InStr(obsdt, ">") + leng, Len(obsdt))
        obsdt = Mid(obsdt, 1, InStr(obsdt, "<") - 1)


        Dim obsdt2 As Date
        obsdt2 = obsdt >>> here is where the error occurs
        
        Rows("1:1").Select
        Set rng = Selection.Find(What:="ÚLTIMA OBSER.", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)
        coluna = rng.Column
        Cells(k, coluna) = obsdt2
        Range("A" & k).Select
    End If
    
    ''observação responsável
    If InStr(allHTML, "Responsável") > 0 Then
        leng = Len("Responsável")
        obsresp = Mid(allHTML, InStr(allHTML, "Responsável") + leng, Len(allHTML))
        leng = Len("conteudo")
        obsresp = Mid(obsresp, InStr(obsresp, "conteudo") + leng, Len(obsresp))
        leng = Len("<small><font")
        obsresp = Mid(obsresp, InStr(obsresp, "<small><font") + leng, Len(obsresp))
        leng = Len(">")
        obsresp = Mid(obsresp, InStr(obsresp, ">") + leng, Len(obsresp))
        leng = Len("<small><font")
        obsresp = Mid(obsresp, InStr(obsresp, "<small><font") + leng, Len(obsresp))
        leng = Len("<small><font")
        obsresp = Mid(obsresp, InStr(obsresp, "<small><font") + leng, Len(obsresp))
        leng = Len(">")
        obsresp = Mid(obsresp, InStr(obsresp, ">") + leng, Len(obsresp))
        obsresp = Mid(obsresp, 1, InStr(obsresp, "<") - 1)
        
        
        Rows("1:1").Select
        Set rng = Selection.Find(What:="ÚLTIMA OBSER.", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)
        coluna = rng.Column
        Cells(k, coluna).ClearComments
        Cells(k, coluna).AddComment obsresp
        Range("A" & k).Select
    End If
    ie.Quit
    Set ie = Nothing
Next k


End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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