I am trying to parse stock holdings for certain companies but I am running into trouble because they are not uniform in their form. The data has a general form but each company uses a slightly different style for the forms. These differences are hamstringing my efforts to effectively parse the data.
I have attempted to parse the data using the split function to get it into a more manageable form, and then use various comparisons to tease out the right information. This, however, has not panned out like I hoped.
Below are some sample data forms and some of my (albeit poorly written and structured) VBA to try and solve the problem.
3COM CORP COM 885535104 6,987 1,700,000 SH OTHER 01 1,700,000
11 HILTON HOTELS CORPORATION common 432848109 3,490 100,000 SH CALL Shared-Defined NONE
Prudential Financial, Inc. COM 744320102 $ 1,796,511 20,923,720 SH SOLE 20,923,720
I am trying to extract the same fields from each, such as name or number of shares.
here is some of my code to try and accomplish this. this seems to work the data if it is formatted correctly, but I would like write a general parser.
txt = ActiveCell.Value
x = Split(txt, " ")
name = ""
cusip = ""
shrs = ""
Do While name = "" And cusip = "" And shrs = ""
For i = 0 To i = UBound(x)
If i = 0 Then
name = x(i)
End If
If Len(x(i)) = 9 And InStr(1, x(i), " ") = False And InStr(1, x(i), ",") = False Then
cusip = x(i)
End If
If i > 0 Then
If Len(x(i)) >= 4 And IsNumeric(Right(x(i - 1), 2)) = True And x(i - 1) <> cusip Then
shrs = x(i)
End If
End If
Next i
Loop
Any help or tips would be much appreciated. Thanks.
I have attempted to parse the data using the split function to get it into a more manageable form, and then use various comparisons to tease out the right information. This, however, has not panned out like I hoped.
Below are some sample data forms and some of my (albeit poorly written and structured) VBA to try and solve the problem.
3COM CORP COM 885535104 6,987 1,700,000 SH OTHER 01 1,700,000
11 HILTON HOTELS CORPORATION common 432848109 3,490 100,000 SH CALL Shared-Defined NONE
Prudential Financial, Inc. COM 744320102 $ 1,796,511 20,923,720 SH SOLE 20,923,720
I am trying to extract the same fields from each, such as name or number of shares.
here is some of my code to try and accomplish this. this seems to work the data if it is formatted correctly, but I would like write a general parser.
txt = ActiveCell.Value
x = Split(txt, " ")
name = ""
cusip = ""
shrs = ""
Do While name = "" And cusip = "" And shrs = ""
For i = 0 To i = UBound(x)
If i = 0 Then
name = x(i)
End If
If Len(x(i)) = 9 And InStr(1, x(i), " ") = False And InStr(1, x(i), ",") = False Then
cusip = x(i)
End If
If i > 0 Then
If Len(x(i)) >= 4 And IsNumeric(Right(x(i - 1), 2)) = True And x(i - 1) <> cusip Then
shrs = x(i)
End If
End If
Next i
Loop
Any help or tips would be much appreciated. Thanks.