Extracting a text string Problem

fari1

Active Member
Joined
May 29, 2011
Messages
362
my below code is perfect of extracting my another text string, but when i modify it to extract my another text string, it is not giving me results, trying real hard but unable to find the problem.

the text string to find is
HTML:
BIK=0000055135
out of this line

HTML:
<td bgcolor="#E6E6E6" valign="top" align="left"><a href="/chi-kin/browse-gar?action=getcompany&BIK=0000055135&owner=include&count=100">KELLY SERVICES INC (0000055135) (Filer)</a></td>

Code:
Sub GetCIK()
  Sheets("wquery").Select
  Dim X As Long, LastRow As Long, OutputRow As Long, CellContent As String
  Const StartRow As Long = 1
  Const DataCol As String = "A"
  Const OutputSheet As String = "URLs"
  Const OutputCol As String = "B"
  LastRow = Sheets("wquery").Cells(Rows.Count, DataCol).End(xlUp).Row
  OutputRow = Worksheets(OutputSheet).Cells(Rows.Count, OutputCol).End(xlUp).Row
  For X = StartRow To LastRow
    If LCase(Sheets("wquery").Cells(X, DataCol).Value) Like "*getcompany&""CIK*&*" Then
      OutputRow = OutputRow + 1
      CellContent = Sheets("wquery").Cells(X, DataCol).Value
      Worksheets(OutputSheet).Cells(OutputRow, OutputCol).Value = Split(Mid(CellContent, InStr(1, CellContent, "getcompany&""CIK", vbTextCompare) + 15), """amp")(0)
    End If
  Next
 
Re: Help with the code

it worked on your side? its not giving me error now, but not giving any results either, i changed my outputcol2 to "B"

Yes it has worked on my side.
Send me your worksheet or the code you're using and I might be able to point out the problem.

it doens't have to be the real data you use on but it will certainly help since there may be many exceptions in the real data that I have not thought of...
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
What seems to be the problem?

I've run the code posted previously onto your workbook by renaming the datasheet "wquery"
and destination sheet "Filings" (both without the quotations).

I will send you the email with the attachment.
 
Upvote 0
It's because ... the HTML tag was removed from the code when posting..

[EDIT: here is the code you can use]
HTML:
Sub GetType()
    Dim X As Long, LastRow1 As Long, CellContent As String, lastRow&
    Dim pos1&, pos2&, OutputRow2&
 
    Const StartRow As Long = 1
    Const DataCol As String = "A"
    Const OutputSheet As String = "Filings"
    Const OutputCol2 As String = "C"
 
    lastRow = Sheets("wquery").Cells(Rows.Count, DataCol).End(xlUp).Row
    OutputRow2 = Worksheets(OutputSheet).Cells(Rows.Count, OutputCol2).End(xlUp).Row
 
    For X = StartRow To lastRow
        If Sheets("wquery").Cells(X, DataCol).Value Like "*""nowrap*</td>*" Then
            OutputRow2 = OutputRow2 + 1
            CellContent = Sheets("wquery").Cells(X, DataCol).Value
            pos1 = InStr(1, CellContent, """nowrap""")
            pos2 = InStr(1, CellContent, "</td>")
            If pos1 = 0 Or pos2 = 0 Then GoTo continue
            Worksheets(OutputSheet).Cells(OutputRow2, OutputCol2).Value = Mid(CellContent, pos1 + 9, pos2 - pos1 - 9)
        End If
continue:
    Next X
End Sub
 
Last edited:
Upvote 0
i mean in my fillings sheets, i want the output to start from 2nd row, can't it done to start bring data in output sheet from 2nd row?
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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