Excel精英培训网

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

[已解决]多条件复制粘贴

[复制链接]
发表于 2017-4-21 08:45 | 显示全部楼层 |阅读模式
多条件复制粘贴的VBA
最佳答案
2017-4-21 13:18
  1. Sub tt()
  2.     Dim cel As Range, rng As Range
  3.     Set d = CreateObject("scripting.dictionary")
  4.     Set rng = Selection
  5.     ReDim brr(1 To rng.Cells.Count, 1 To 3)
  6.     For Each cel In rng
  7.         x = cel.Value
  8.         n = n + 1
  9.         brr(n, 1) = x: brr(n, 2) = x: brr(n, 3) = x
  10.         d(x) = ""
  11.     Next
  12.     If d.Count <= 6 Then MsgBox "选择区域中不同数字的个数小于等于6个,不粘贴。": Exit Sub
  13.     For Each cel In ActiveSheet.UsedRange
  14.         If cel.Interior.ColorIndex = 6 Then c = cel.Column: Exit For
  15.     Next
  16.     If Len(c) = 0 Then MsgBox "未找到黄色区域": Exit Sub
  17.    
  18.     r = Cells(65536, c).End(3).Row + 1
  19.     If r < 30 Then r = 30
  20.     Cells(r, c).Resize(n, 3) = brr
  21. End Sub
复制代码

复制粘贴VBA.rar

10.78 KB, 下载次数: 5

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2017-4-21 13:18 | 显示全部楼层    本楼为最佳答案   
  1. Sub tt()
  2.     Dim cel As Range, rng As Range
  3.     Set d = CreateObject("scripting.dictionary")
  4.     Set rng = Selection
  5.     ReDim brr(1 To rng.Cells.Count, 1 To 3)
  6.     For Each cel In rng
  7.         x = cel.Value
  8.         n = n + 1
  9.         brr(n, 1) = x: brr(n, 2) = x: brr(n, 3) = x
  10.         d(x) = ""
  11.     Next
  12.     If d.Count <= 6 Then MsgBox "选择区域中不同数字的个数小于等于6个,不粘贴。": Exit Sub
  13.     For Each cel In ActiveSheet.UsedRange
  14.         If cel.Interior.ColorIndex = 6 Then c = cel.Column: Exit For
  15.     Next
  16.     If Len(c) = 0 Then MsgBox "未找到黄色区域": Exit Sub
  17.    
  18.     r = Cells(65536, c).End(3).Row + 1
  19.     If r < 30 Then r = 30
  20.     Cells(r, c).Resize(n, 3) = brr
  21. End Sub
复制代码

复制粘贴VBA.rar

20.64 KB, 下载次数: 12

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 06:46 , Processed in 0.311456 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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