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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Is the string you're looking for ALWAYS 14 characters long (3Alpha=10Numeric) ?
Does it ALWAYS follow the first semicolon ( ; ) in the string?
 
Upvote 0
You could always split it

At the top of your moduel
Code:
Option Base 0

Inside ur code
Code:
Dim str$()
 
str = Split(Lcase(Sheets("wquery").Cells(X, DataCol).Value), ";")
msgBox str(1)

I don't know any HTML code (just little) so I don't know if this will be okay.
 
Upvote 0
Oops forgot about the string manipulation
Code:
msgBox Left(str(1), Len(str(1)) - 4)
 
'OR
 
msgBox Left(str(1), 14)
 
Upvote 0
hi, but why are u adding msg box into it? the code dont need to have msg box into is, and plz it 'll be very considerate of u, if u write the whole code, combining these strings wrongly may take a lot of time of me and u as well
 
Upvote 0
For instance, yet untested:

Code:
Sub GetCIK()

    Dim X As Long, LastRow 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"

    With Sheets("wquery")
        LastRow = .Cells(.Rows.Count, DataCol).End(xlUp).Row
        OutputRow = Worksheets(OutputSheet).Cells(Rows.Count, OutputCol).End(xlUp).Row
        For X = StartRow To LastRow
            CellContent = .Cells(X, DataCol).Text
            If CellContent Like "*getcompany&""CIK*&*" Then
                Worksheets(OutputSheet).Cells(Rows.Count, OutputCol).End(xlUp).Offset(1).Value = "BIK=" & Split(Split(CellContent, "BIK=")(1), "&")(0)
            End If
        Next
    End With
    
End Sub
 
Upvote 0
Then revise this statement:

If CellContent Like "*getcompany&""CIK*&*" Then
 
Upvote 0
HTML:
If CellContent Like "*getcompany&""CIK*&*" Then

i guess this lines has problems
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,809
Members
452,944
Latest member
2558216095

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