|
- Sub 评级()
- Rows("4:65536").ClearContents
-
- '挑选出所有有评级的股票,放在第4、5行
- arr = Range([a1], Cells(2, [a1].End(xlToRight).Column))
- k = 1
- For i = 1 To UBound(arr, 2)
- If arr(2, i) <> "" Then
- Cells(4, k) = arr(1, i): Cells(5, k) = arr(2, i)
- k = k + 1
- End If
- Next
- Erase arr
-
- ' 把所有评级分解后按日期填入,相同日期填在同一行
- Set d = CreateObject("scripting.dictionary")
- arr = Range([b5], Cells(5, [b5].End(xlToRight).Column))
- For i = 1 To UBound(arr, 2)
- brr = Split(arr(1, i), "/")
- For j = 0 To UBound(brr)
- r = Cells(65536, 1).End(3).Row + 1
- riqi = GetNum(brr(j)) '函数GetNum:把一个字符串中的数字全部筛选出来
- 'pinji = Replace(brr(j), "-" & riqi, "") '显示评级的全部内容
- pinji = Split(brr(j), "(")(0) '仅显示评级的级别(AAA、AA+等)
- If d.exists(riqi) = False Then
- d(riqi) = ""
- Else
- r = Range("A1:A" & r).Find(riqi).Row
- End If
- Cells(r, 1) = riqi: Cells(r, i + 1) = pinji
- Next
- Next
- '把填好后的评级按日期进行排序
- Set myrng = Range([a6], Cells([a6].End(xlDown).Row, [a4].End(xlToRight).Column))
- myrng.Sort Key1:=Range("A2:A" & [a6].End(xlDown).Row), Order1:=xlAscending
- Rows(5).Delete '删除辅助行
- End Sub
- Function GetNum(str) '把一个字符串中的数字全部筛选出来
- With CreateObject("VBSCRIPT.REGEXP") '正则表达式
- .Global = True
- .Pattern = "[^0-9.]" '数字模式
- GetNum = .Replace(str, "")
- End With
- End Function
复制代码 请看附件,简化了一下,只把有评级内容的股票筛选了出来。 |
|