Excel精英培训网

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

[VBA] VBA用逗号连接数字和条件

[复制链接]
发表于 2016-9-11 17:05 | 显示全部楼层 |阅读模式
VBA用逗号连接数字和条件


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-9-11 21:07 | 显示全部楼层
祝您好运:
  1. Sub wanao()
  2.     Dim x As Integer, y As Integer, a As Integer
  3.     Dim str As String, s(1 To 2) As String
  4.     s(1) = "/0~1~2~3~4"
  5.     s(2) = "/0~1~2~3"
  6.     For x = 1 To 3
  7.         a = 0
  8.         str = ""
  9.         For y = 1 To 13
  10.             If Cells(x, y) <> "" Then a = a + 1 Else Exit For
  11.             If str = "" Then str = Cells(x, y) Else str = str & "," & Cells(x, y)
  12.         Next
  13.         If a > 10 Then str = str & s(1) Else str = str & s(2)
  14.         Cells(x, "n") = str
  15.     Next
  16. End Sub
复制代码

评分

参与人数 1 +1 收起 理由
laoau138 + 1 来学习

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2016-9-11 21:12 | 显示全部楼层
wanao2008 发表于 2016-9-11 21:07
祝您好运:

这个没有那么容易,

刚有人写了自定函数,

Function 连接(RNG As Range)
x = Application.Count(RNG)
arr = Application.Transpose(Application.Transpose(RNG(1).Resize(, x)))
连接 = Join(arr, ",") & "/0~1~2~3" & IIf(x > 10, "~4", "")
End Function



回复

使用道具 举报

发表于 2016-9-12 07:55 | 显示全部楼层
wanao2008 发表于 2016-9-11 21:07
祝您好运:

高手啊
回复

使用道具 举报

发表于 2016-9-15 09:32 | 显示全部楼层

一直在学习,一直在努力!加油!!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 19:00 , Processed in 0.243852 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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