Excel精英培训网

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

[已解决]复制问题再重新排序

[复制链接]
发表于 2013-2-21 13:08 | 显示全部楼层 |阅读模式
第一:数据源在A列,根据E列选择“√”在数据源“%”上复制。结果如G列G13。
第二:E列选择在%以下对应坐标在“M30”之上复制,结果如G44到G46。
第三:重新递增排序如H列(如H13,H44)
最后:把结果放A列。E 列没有“√”,提示没有资料处理。帮忙写个代码,谢谢!!!

最佳答案
2013-2-22 18:05
  1. Sub 数据处理()
  2.     'On Error Resume Next
  3.    
  4.     Dim rgChoose As Range
  5.     Dim rgPer As Range
  6.     Dim rgFin As Range
  7.     Dim str$
  8.     Dim i&
  9.     Dim Address$
  10.    
  11.     Application.ScreenUpdating = False

  12.     Set rgChoose = Range("e:e").Find(what:="√", lookat:=xlWhole)
  13.    
  14.     If rgChoose Is Nothing Then
  15.         MsgBox "没有资料处理"
  16.         Exit Sub
  17.     End If
  18.    
  19.     Set rgPer = Range("a:a").Find(what:="%", lookat:=xlWhole)
  20.     If rgPer Is Nothing Then MsgBox "A列无%": Exit Sub
  21.    
  22.     Cells(rgChoose.Row, 1).Copy
  23.     rgPer.Insert
  24.    
  25.     Application.CutCopyMode = False
  26.    
  27.     str = rgPer.Offset(-1)
  28.     Mid(str, 2, 2) = Val(Mid(rgPer.Offset(-2), 2, 2)) + 1
  29.     rgPer.Offset(-1) = str
  30.    
  31.     str = rgChoose.Offset(, -3)
  32.     str = Left(str, 1) & Right(str, Len(str) - 1) / 1

  33.     Set rgChoose = Nothing
  34.     Set rgChoose = Range("a:a").Find(what:=str, lookat:=xlWhole)
  35.     If rgChoose Is Nothing Then MsgBox "在A列没有找到" & str: Exit Sub
  36.    
  37.     If Range("a:a").Find(what:="M30", lookat:=xlWhole) Is Nothing Then MsgBox "A列无结束标志M30": Exit Sub
  38.    
  39.     i = rgChoose.Row + 1
  40.     Do While Not (Cells(i, 1) Like "T#*" Or Cells(i, 1) Like "M30" Or Len(Cells(i, 1)) = 0)
  41.         i = i + 1
  42.     Loop
  43.     Range(rgChoose, Cells(i - 1, 1)).Copy
  44.    
  45.     Set rgFin = Range("a:a").Find(what:="M30", lookat:=xlWhole)
  46.     Address = rgFin.Address
  47.     rgFin.Insert
  48.    
  49.     Application.CutCopyMode = False
  50.     str = Left(rgPer.Offset(-1).Value, 3)
  51.     Range(Address) = str

  52. End Sub
复制代码

Book1.rar

296.77 KB, 下载次数: 31

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2013-2-21 13:38 | 显示全部楼层
楼主整得越来越深入了,你的题都快做不出来了,{:412:}
回复

使用道具 举报

 楼主| 发表于 2013-2-21 13:50 | 显示全部楼层
hwc2ycy 发表于 2013-2-21 13:38
楼主整得越来越深入了,你的题都快做不出来了,

呵呵,谢谢啦!!!大师!!!
回复

使用道具 举报

发表于 2013-2-21 18:12 | 显示全部楼层
本帖最后由 hwc2ycy 于 2013-2-21 18:15 编辑
  1. Sub 数据处理()
  2.     'On Error Resume Next
  3.     Dim rg As Range
  4.     Dim str$
  5.     Dim rgper As Range
  6.     Application.ScreenUpdating = False
  7.    
  8.     Set rg = Range("e:e").Find(what:="√", lookat:=xlWhole)
  9.     If rg Is Nothing Then
  10.         MsgBox "没有资料处理"
  11.         Exit Sub
  12.     End If
  13.     Set rgper = Range("a:a").Find(what:="%", lookat:=xlWhole)
  14.     if rgper is nothing then msgbox "A列无%":exit sub
  15.     Cells(rg.Row, 1).Copy
  16.     rgper.Insert
  17.     Application.CutCopyMode = False
  18.     str = rgper.Offset(-1)
  19.     Mid(str, 2, 2) = Val(Mid(rgper.Offset(-2), 2, 2)) + 1
  20.     rgper.Offset(-1) = str
  21.     Application.ScreenUpdating = True
  22.     MsgBox "处理完成"
  23. End Sub
复制代码

评分

参与人数 1 +3 收起 理由
fangniuji + 3 很给力!

查看全部评分

回复

使用道具 举报

发表于 2013-2-21 18:20 | 显示全部楼层
偷了懒,只针对2位数做处理,要是你数据量多了,达到3位数字了,这代码就不灵光了。
回复

使用道具 举报

 楼主| 发表于 2013-2-22 09:12 | 显示全部楼层
hwc2ycy 发表于 2013-2-21 18:20
偷了懒,只针对2位数做处理,要是你数据量多了,达到3位数字了,这代码就不灵光了。

非常非常谢谢你,谢谢!!!第一要求以帮我处理好。谢谢!!第二:E列选择在%以下对应坐标在“M30”之上复制,结果如G44到G46。 第二再帮我一下,谢谢!!!
回复

使用道具 举报

 楼主| 发表于 2013-2-22 09:14 | 显示全部楼层
hwc2ycy 发表于 2013-2-21 18:20
偷了懒,只针对2位数做处理,要是你数据量多了,达到3位数字了,这代码就不灵光了。

没有三位数,不超过100,谢谢!!!
回复

使用道具 举报

发表于 2013-2-22 09:35 | 显示全部楼层
  1. Sub 数据处理()
  2.     'On Error Resume Next
  3.     Dim rg As Range
  4.     Dim str$
  5.     Dim rgper As Range
  6.     Dim i&
  7.     Application.ScreenUpdating = False
  8.    
  9.     Set rg = Range("e:e").Find(what:="√", lookat:=xlWhole)
  10.     If rg Is Nothing Then
  11.         MsgBox "没有资料处理"
  12.         Exit Sub
  13.     End If
  14.     Set rgper = Range("a:a").Find(what:="%", lookat:=xlWhole)
  15.     If rgper Is Nothing Then MsgBox "A列无%": Exit Sub
  16.     Cells(rg.Row, 1).Copy
  17.     rgper.Insert
  18.     Application.CutCopyMode = False
  19.     str = rgper.Offset(-1)
  20.     Mid(str, 2, 2) = Val(Mid(rgper.Offset(-2), 2, 2)) + 1
  21.     rgper.Offset(-1) = str
  22.     str = rg.Offset(, -3)
  23.     str = Left(str, 1) & Val(Right(str, Len(str) - 1))
  24.    
  25.     Set rg = Nothing
  26.     Set rg = Range("a:a").Find(what:=str, lookat:=xlWhole)
  27.     If rg Is Nothing Then MsgBox "在A列没有找到" & str: Exit Sub
  28.     If Range("a:a").Find(what:="M30", lookat:=xlWhole) Is Nothing Then MsgBox "A列无结束标志M30": Exit Sub
  29.     i = rg.Row + 1
  30.     Do While Not (Cells(i, 1) Like "T#*" Or Cells(i, 1) Like "M30") Or Len(Cells(i, 1)) > 0
  31.         i = i + 1
  32.     Loop
  33.     Range(rg, Cells(i - 1, 1)).Copy
  34.    
  35.     Range("a:a").Find(what:="M30", lookat:=xlWhole).Insert
  36.     Application.CutCopyMode = False
  37.     msgbox "数据处理完成"
  38. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2013-2-22 11:00 | 显示全部楼层
hwc2ycy 发表于 2013-2-22 09:35

出现 400,再麻烦一下,谢谢!!!
22.JPG
回复

使用道具 举报

发表于 2013-2-22 11:54 | 显示全部楼层
  1. Sub 数据处理()
  2.     'On Error Resume Next
  3.     Dim rg As Range
  4.     Dim str$
  5.     Dim rgper As Range
  6.     Dim i&
  7.     Application.ScreenUpdating = False

  8.     Set rg = Range("e:e").Find(what:="√", lookat:=xlWhole)
  9.     If rg Is Nothing Then
  10.         MsgBox "没有资料处理"
  11.         Exit Sub
  12.     End If
  13.     Set rgper = Range("a:a").Find(what:="%", lookat:=xlWhole)
  14.     If rgper Is Nothing Then MsgBox "A列无%": Exit Sub
  15.     Cells(rg.Row, 1).Copy
  16.     rgper.Insert
  17.     Application.CutCopyMode = False
  18.     str = rgper.Offset(-1)
  19.     Mid(str, 2, 2) = Val(Mid(rgper.Offset(-2), 2, 2)) + 1
  20.     rgper.Offset(-1) = str
  21.     str = rg.Offset(, -3)
  22.     str = Left(str, 1) & Val(Right(str, Len(str) - 1))

  23.     Set rg = Nothing
  24.     Set rg = Range("a:a").Find(what:=str, lookat:=xlWhole)
  25.     If rg Is Nothing Then MsgBox "在A列没有找到" & str: Exit Sub
  26.     If Range("a:a").Find(what:="M30", lookat:=xlWhole) Is Nothing Then MsgBox "A列无结束标志M30": Exit Sub
  27.     i = rg.Row + 1
  28.     Do While Not (Cells(i, 1) Like "T#*" Or Cells(i, 1) Like "M30" Or Len(Cells(i, 1)) = 0)
  29.         i = i + 1
  30.     Loop
  31.     Range(rg, Cells(i - 1, 1)).Copy

  32.     Range("a:a").Find(what:="M30", lookat:=xlWhole).Insert
  33.     Application.CutCopyMode = False
  34.     msgbox "数据处理完成"
  35. End Sub
复制代码

评分

参与人数 1 +3 收起 理由
fangniuji + 3 很给力!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 00:53 , Processed in 0.534426 second(s), 15 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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