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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
HTML:
If CellContent Like "*getcompany&""CIK*&*" Then

dont u think, it should be like this?
i've tested it like this as well, but nothing
 
Upvote 0
Code:
If CellContent Like "*getcompany*BIK*" Then

Please use
Code:
 tags instead of [HTML] tags.
 
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

It was there to let you 'test' the code and notify you the result.

Anyways, here is the implemented solution,
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*BIK*" 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
hi kpark,the code is not working, y dun u test this code on your side as well, if it does work your side, then surely there's some problem on my side, then i'll try to post somehow my sample workbook. it'll be really helpful.
 
Upvote 0
hi kpark,the code is not working, y dun u test this code on your side as well, if it does work your side, then surely there's some problem on my side, then i'll try to post somehow my sample workbook. it'll be really helpful.

That would be great.
I realized I've made a mistake in the code but I'll test with your workbook first before I post the code.

@wigi: sorry for the confusion (two answerers on this question O_o).
 
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