boxhamster
New Member
- Joined
- Jan 12, 2016
- Messages
- 14
I had this script made by a mate once, but now something is not working anymore. It's says "done", but actually cells were not populated with values. What it does it takes a company name in cell A and then populates cells B-E with CRN SIC Postcode Addresss.
I'd be very grateful for some help. From what I see, it enters the company and searches for it, but then when trying to go to /company/CRN number the pages doesn't work. Not sure how to fix this?
Thanks for looking and helping.
I'd be very grateful for some help. From what I see, it enters the company and searches for it, but then when trying to go to /company/CRN number the pages doesn't work. Not sure how to fix this?
Thanks for looking and helping.
Code:
Sub companieshouse()
Dim lastrow As Long
Dim whblock() As String
Dim siccon As Integer
Dim remspace As String
Dim final As String
Dim ie As New InternetExplorer
siccon = 0
lastrow = ActiveSheet.Range("A:A").End(xlDown).Row
ie.Visible = True
For I = 2 To lastrow
remspace = Replace(ActiveSheet.Range("A" & I).Value, " ", "+")
final = Replace(remspace, "&", "%26")
ie.navigate "[URL]https://beta.companieshouse.gov.uk/search/companies?q=[/URL]" & final
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Dim doc As New HTMLDocument
Set doc = ie.document
Dim name, name2 As String
name = doc.getElementsByTagName("li")(4).innerText
If Not doc.getElementsByTagName("li")(4) Is Nothing Then
whblock() = Split(name, vbCrLf)
If InStr(1, whblock(0), UCase(ActiveSheet.Range("A" & I).Value)) > 0 Then
ActiveSheet.Range("B" & I).Value = Trim(Mid(whblock(1), 1, InStr(1, whblock(1), "-") - 1))
ActiveSheet.Range("D" & I).Value = Mid(whblock(2), InStrRev(whblock(2), ",") + 1)
ActiveSheet.Range("E" & I).Value = Mid(whblock(2), 1, InStrRev(whblock(2), ",") - 1)
End If
[B]ie.navigate "[URL]https://beta.companieshouse.gov.uk/company/[/URL]" & ActiveSheet.Range("B" & I).Value[/B]
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
Do Until doc.getElementById("sic" & siccon) Is Nothing
name2 = name2 & vbCrLf & doc.getElementById("sic" & siccon).innerText
siccon = siccon + 1
Loop
ActiveSheet.Range("C" & I).Value = Replace(name2, vbCrLf, "", 1, 1)
name = ""
name2 = ""
Erase whblock()
siccon = 0
End If
Next
ie.Quit
MsgBox "Done"
End Sub