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
 
i guess u still didn't separate the two codes, they are still still referencing two columns, why r they?
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
some part of your code is up there as well, is it also the part of the code, right?

What do you mean?

Some variables are not used but that's nothing to worry about since it won't cause a huge delay.

And it is separate now.. if that's what you mean to ask.
 
Upvote 0
i guess u still didn't separate the two codes, they are still still referencing two columns, why r they?

that's because I was lazy to delete one of them. you can do that tho.
Just try it yourself, the code is extremely readable.
(What variables I am using and such..)
 
Upvote 0
its giving error invalid call or procedure element on this line
Code:
 Worksheets(OutputSheet).Cells(OutputRow2, OutputCol2).Value = Mid(CellContent, pos1 + 9, pos2 - pos1 - 9)
 
Upvote 0
Help with the code

Code:
Option Base 0
Option Explicit
Sub GetType()
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 = "Filings"
    Const OutputCol1 As String = "A"
    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 "*""nowrap*" Then
        OutputRow2 = OutputRow2 + 1
        CellContent = Sheets("wquery").Cells(X, DataCol).Value
        pos1 = InStr(1, CellContent, """nowrap""")
        pos2 = InStr(1, CellContent, "")
        Worksheets(OutputSheet).Cells(OutputRow2, OutputCol2).Value = Mid(CellContent, pos1 + 9, pos2 - pos1 - 9)
        End If
        Next X
End Sub

i need to extract the text from in between
HTML:
nowrap"> and </
i-e 10-Q or whatever text is in between from the below line. the above code is not working somehow,any help on it

HTML:
<td nowrap="nowrap">10-Q</td>
 
Upvote 0
Re: Help with the code

change
Code:
pos2 = InStr(1, CellContent, "")

to
Code:
pos2 = InStr(1, Cellcontent, " < / t d > </TD>" )

without the spaces
 
Upvote 0
Code:
Option Base 0
Option Explicit
Sub GetType()
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 = "Filings"
    Const OutputCol1 As String = "A"
    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 "*""nowrap*" Then
        OutputRow2 = OutputRow2 + 1
        CellContent = Sheets("wquery").Cells(X, DataCol).Value
        pos1 = InStr(1, CellContent, """nowrap""")
        pos2 = InStr(1, CellContent, "")
        Worksheets(OutputSheet).Cells(OutputRow2, OutputCol2).Value = Mid(CellContent, pos1 + 9, pos2 - pos1 - 9)
        End If
        Next X
End Sub


i could not understand so made some changes that i could get to know
 
Upvote 0
Re: Help with the code

This html tag manipulation is really annoying because the forum can't handle it very well..

So, basically what my previous reply is... "" should be replaced with the end tag of td.
The /td with < > around it.
So giving you
""

html tag = /td

So,
Code:
pos2 = InStr(1, Cellcontent, "/td with <> around it")
</TD>
 
Upvote 0
again the same error, invalid procedure and call on this line

Worksheets(OutputSheet).Cells(OutputRow2, OutputCol2).Value = Mid(CellContent, pos1 + 9, pos2 - pos1 - 9)

also plz tell me, should i use the outputrow1 or 2, because i just need one column paste
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
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