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
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this then..

It worked in the workbook you've sent me.
Btw, your HTML code says "BIK=####" while in your workbook, it's "CIK"
Code:
Option Base 0
Sub GetCIK()
  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 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 = Left$(Split(CellContent, ";")(1), 14)
    End If
Next
End Sub
 
Upvote 0
oh sorry, i didn't see the post,let me try, i knew it was CIK, on my side, i was doing CIK
 
Upvote 0
can u plz extract one more string out of it

HTML:
<td nowrap="nowrap">10-Q</td>

i want to extract the text string between "nowrap and td" i-e 10-Q or whatever text in between
 
Upvote 0
Is that the whole line of the code?

Try:
Rich (BB code):
Option Base 0
Option Explicit
Sub GetCIK()
   Dim X As Long, LastRow1 As Long, OutputRow1 As Long, CellContent As String, LastRow&
   Dim pos1&, pos2&, OutputRow2&
 
   Const StartRow As Long = 1
   Const DataCol As String = "A"
   Const OutputSheet As String = "URLs"
   Const OutputCol1 As String = "B"
   Const OutputCol2 As String = "C"
 
   LastRow = Sheets("wquery").Cells(Rows.Count, DataCol).End(xlUp).Row
   OutputRow1 = Worksheets(OutputSheet).Cells(Rows.Count, OutputCol1).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 "*getcompany*CIK*" Then
         OutputRow1 = OutputRow1 + 1
         CellContent = Sheets("wquery").Cells(X, DataCol).Value
         Worksheets(OutputSheet).Cells(OutputRow1, OutputCol1).Value = Left$(Split(CellContent, ";")(1), 14)
       End If
 
       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>")
           Worksheets(OutputSheet).Cells(OutputRow2, OutputCol2).Value = Mid(CellContent, pos1 + 9, pos2 - pos1 - 9)
       End If
   Next X
 
End Sub
 
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