Excel精英培训网

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

[已解决]VBA多种方法连接A1 D1单元格字符

[复制链接]
发表于 2017-5-29 22:48 | 显示全部楼层 |阅读模式
本帖最后由 laoau138 于 2017-5-30 08:20 编辑

VBA多种方法连接A1 D1单元格字符


'VBA多种方法连接A1: D1单元格字符

'一共能写多少种方法


Sub 第一种方法()
Range("A6").Value = Join(Application.Transpose(Application.Transpose(Range("A1:D1").Value)), "")
End Sub

Sub 第二种方法()
[a7] = [a1] & [b1] & [c1] & [d1]
End Sub

最佳答案
2017-5-30 03:39
本帖最后由 france723 于 2017-5-30 03:42 编辑

仅仅提供一个思路 :
  1. Sub aaa()
  2. Dim ar, a, b, c, d, s, n
  3. ar = Range("a1:d1")
  4. n = 6
  5. For Each a In ar
  6.     For Each b In ar
  7.         For Each c In ar
  8.             If b <> a And a <> c And b <> c Then
  9.                 For Each d In ar
  10.                     If d <> a And d <> b And d <> c Then
  11.                         s = d
  12.                     End If
  13.                 Next d
  14.                 Cells(n, 1) = a & b & c & s
  15.                 Cells(n, 2) = "第" & n - 5 & "种"
  16.                 n = n + 1
  17.             End If
  18.         Next c
  19.     Next b
  20. Next a
  21. End Sub
复制代码


VBA多种方法连接A1 D1单元格字符.png

VBA多种方法连接A1 D1单元格字符.rar

12.67 KB, 下载次数: 6

发表于 2017-5-30 03:39 | 显示全部楼层    本楼为最佳答案   
本帖最后由 france723 于 2017-5-30 03:42 编辑

仅仅提供一个思路 :
  1. Sub aaa()
  2. Dim ar, a, b, c, d, s, n
  3. ar = Range("a1:d1")
  4. n = 6
  5. For Each a In ar
  6.     For Each b In ar
  7.         For Each c In ar
  8.             If b <> a And a <> c And b <> c Then
  9.                 For Each d In ar
  10.                     If d <> a And d <> b And d <> c Then
  11.                         s = d
  12.                     End If
  13.                 Next d
  14.                 Cells(n, 1) = a & b & c & s
  15.                 Cells(n, 2) = "第" & n - 5 & "种"
  16.                 n = n + 1
  17.             End If
  18.         Next c
  19.     Next b
  20. Next a
  21. End Sub
复制代码


评分

参与人数 2 +33 收起 理由
小小菜鸟学EXCEL + 24 给你点24个赞
laoau138 + 9 赞一个

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2017-5-30 08:55 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 15:36 , Processed in 0.210759 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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