Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1894|回复: 6

[已解决]求助个股研报标题汇总显示,谢谢

[复制链接]
发表于 2017-9-20 07:58 | 显示全部楼层 |阅读模式
求助个股研报标题汇总显示,谢谢
最佳答案
2017-9-21 10:28
  1. Sub ceshi()
  2.    
  3.     Dim i As Long, j As Long, i1 As Long, j1 As Long, szh As Long, szl As Long, arr As Variant
  4.     Dim sl As String, tt As Long
  5.     Dim gpdm As Variant, gpdm2 As Variant, gpdm3 As Variant
  6.     Application.ScreenUpdating = False
  7.     Application.DisplayAlerts = False
  8.     szh = Range("a2").CurrentRegion.Rows.Count
  9.     szl = Range("a2").CurrentRegion.Columns.Count
  10.     arr = Range(Cells(2, "a"), Cells(szh, szl))
  11.     Range(Cells(2, "a"), Cells(szh, szl)).Select
  12.     ActiveSheet.Sort.SortFields.Clear
  13.     ActiveSheet.Sort.SortFields.Add Key:=Range(Cells(2, "a"), Cells(szh, "a")), _
  14.         SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  15.     With ActiveSheet.Sort
  16.         .SetRange Range(Cells(2, "a"), Cells(szh, szl))
  17.         .Header = xlGuess
  18.         .MatchCase = False
  19.         .Orientation = xlTopToBottom
  20.         .SortMethod = xlPinYin
  21.         .Apply
  22.     End With
  23.     i = 2
  24.     j = i + 1
  25.     i1 = 2
  26.     Do
  27.         If Cells(i, "a") = "" Then
  28.             Exit Do
  29.         End If
  30.         Do
  31.             If Cells(j, "a") = "" Then
  32.                 Exit Do
  33.             End If
  34.             If Cells(i, "a") = Cells(j, "a") Then
  35.                 j = j + 1
  36.             Else
  37.                 Exit Do
  38.             End If
  39.         Loop
  40.         gpdm = Split(Cells(i, "a"), ".")
  41.         If Left(gpdm(0), 1) = 0 Or Left(gpdm(0), 1) = 3 Then
  42.             gpdm3 = "0" & "|" & gpdm(0) & "|"
  43.         ElseIf Left(gpdm(0), 1) = 6 Then
  44.             gpdm3 = "1" & "|" & gpdm(0) & "|"
  45.         End If
  46.         sl = ""
  47.         If i < j - 1 Then
  48.             For tt = 1 To 2
  49.                 If tt = 1 Then
  50.                     gpdm2 = Cells(i, "e") & "," & Cells(i, "i") & ";"
  51.                 ElseIf tt = 2 Then
  52.                     gpdm2 = Cells(i, "e") & "," & Cells(i, "i")
  53.                 End If
  54.                 sl = sl & gpdm2
  55.                 i = i + 1
  56.             Next
  57.         ElseIf i = j - 1 Then
  58.             gpdm2 = Cells(i, "e") & "," & Cells(i, "i")
  59.             sl = sl & gpdm2
  60.             i = i + 1
  61.         End If
  62.         Cells(i1, "n") = gpdm3 & sl & "|0"
  63.         i = j
  64.         j = i + 1
  65.         i1 = i1 + 1
  66.     Loop
  67.     Range(Cells(2, "a"), Cells(szh, szl)) = arr
  68.     Application.ScreenUpdating = True
  69.     Application.DisplayAlerts = True
  70. End Sub
复制代码
研报标题.zip (69.89 KB, 下载次数: 5)

研报标题.rar

46.78 KB, 下载次数: 3

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2017-9-20 13:09 | 显示全部楼层
回复

使用道具 举报

发表于 2017-9-20 17:59 | 显示全部楼层
输出结果可以按照股票代码从小到大排序吗
回复

使用道具 举报

 楼主| 发表于 2017-9-20 19:45 | 显示全部楼层
wc110wc110 发表于 2017-9-20 17:59
输出结果可以按照股票代码从小到大排序吗

可以,怎么排序都可以
回复

使用道具 举报

发表于 2017-9-21 10:28 | 显示全部楼层    本楼为最佳答案   
  1. Sub ceshi()
  2.    
  3.     Dim i As Long, j As Long, i1 As Long, j1 As Long, szh As Long, szl As Long, arr As Variant
  4.     Dim sl As String, tt As Long
  5.     Dim gpdm As Variant, gpdm2 As Variant, gpdm3 As Variant
  6.     Application.ScreenUpdating = False
  7.     Application.DisplayAlerts = False
  8.     szh = Range("a2").CurrentRegion.Rows.Count
  9.     szl = Range("a2").CurrentRegion.Columns.Count
  10.     arr = Range(Cells(2, "a"), Cells(szh, szl))
  11.     Range(Cells(2, "a"), Cells(szh, szl)).Select
  12.     ActiveSheet.Sort.SortFields.Clear
  13.     ActiveSheet.Sort.SortFields.Add Key:=Range(Cells(2, "a"), Cells(szh, "a")), _
  14.         SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  15.     With ActiveSheet.Sort
  16.         .SetRange Range(Cells(2, "a"), Cells(szh, szl))
  17.         .Header = xlGuess
  18.         .MatchCase = False
  19.         .Orientation = xlTopToBottom
  20.         .SortMethod = xlPinYin
  21.         .Apply
  22.     End With
  23.     i = 2
  24.     j = i + 1
  25.     i1 = 2
  26.     Do
  27.         If Cells(i, "a") = "" Then
  28.             Exit Do
  29.         End If
  30.         Do
  31.             If Cells(j, "a") = "" Then
  32.                 Exit Do
  33.             End If
  34.             If Cells(i, "a") = Cells(j, "a") Then
  35.                 j = j + 1
  36.             Else
  37.                 Exit Do
  38.             End If
  39.         Loop
  40.         gpdm = Split(Cells(i, "a"), ".")
  41.         If Left(gpdm(0), 1) = 0 Or Left(gpdm(0), 1) = 3 Then
  42.             gpdm3 = "0" & "|" & gpdm(0) & "|"
  43.         ElseIf Left(gpdm(0), 1) = 6 Then
  44.             gpdm3 = "1" & "|" & gpdm(0) & "|"
  45.         End If
  46.         sl = ""
  47.         If i < j - 1 Then
  48.             For tt = 1 To 2
  49.                 If tt = 1 Then
  50.                     gpdm2 = Cells(i, "e") & "," & Cells(i, "i") & ";"
  51.                 ElseIf tt = 2 Then
  52.                     gpdm2 = Cells(i, "e") & "," & Cells(i, "i")
  53.                 End If
  54.                 sl = sl & gpdm2
  55.                 i = i + 1
  56.             Next
  57.         ElseIf i = j - 1 Then
  58.             gpdm2 = Cells(i, "e") & "," & Cells(i, "i")
  59.             sl = sl & gpdm2
  60.             i = i + 1
  61.         End If
  62.         Cells(i1, "n") = gpdm3 & sl & "|0"
  63.         i = j
  64.         j = i + 1
  65.         i1 = i1 + 1
  66.     Loop
  67.     Range(Cells(2, "a"), Cells(szh, szl)) = arr
  68.     Application.ScreenUpdating = True
  69.     Application.DisplayAlerts = True
  70. End Sub
复制代码
研报标题.zip (69.89 KB, 下载次数: 5)
回复

使用道具 举报

发表于 2017-9-21 10:29 | 显示全部楼层
jddsky 发表于 2017-9-20 19:45
可以,怎么排序都可以

你看一下,如果正确请设置为最佳答案,谢谢
回复

使用道具 举报

 楼主| 发表于 2017-9-25 20:51 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-24 10:43 , Processed in 1.138820 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表