ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: nifeng123

[求助] 一个客户多列信息转成一行

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-2-22 21:03 | 显示全部楼层
carlostevez1984 发表于 2019-2-22 15:18
烦请您赐教
For j = 1 To 10  这个10:意思是原始数据的10列吧
For j = 1 To 4   这个4:是客户名称 ...

是电话后面的4列

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2019-2-22 21:23 | 显示全部楼层
'假设E列有序,,,

Option Explicit

Sub test()
  Dim arr, i, j, m, n
  arr = [a1].CurrentRegion.Offset(1)
  ReDim brr(1 To UBound(arr, 1), 1 To 6 + 4 * 20) '最大支持20组,自己修改
  m = 1: n = 6
  For i = 1 To UBound(arr, 1) - 1
    For j = 7 To 10
      n = n + 1: brr(m, n) = arr(i, j)
    Next
    If arr(i, 5) <> arr(i + 1, 5) Then
      For j = 1 To 6: brr(m, j) = arr(i, j): Next
      m = m + 1: n = 6
    End If
  Next
  [a31].Resize(m - 1, UBound(brr, 2)) = brr
End Sub

TA的精华主题

TA的得分主题

发表于 2019-2-22 23:38 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
只需要4行代码就能搞定》》》》》
  1. # -*- coding: utf-8 -*-
  2. # version: Python 3.7.0
  3. from collections import defaultdict

  4. scro = [
  5.     ["demao","GC",123456,"1","张三","SD",12345456644,"XX1","移动电话","非亲属"],
  6.     ["demao","GC",123456,"1","张三","SD",12345456645,"XX2","E-mail","客户"],
  7.     ["demao","GC",123456,"1","张三","SD",12345456646,"XX3","移动电话","非亲属"],
  8.     ["demao","GC",123456,"1","张三","SD",12345456647,"XX4","E-mail","客户"],
  9.     ["demao","GC",123456,"1","张三","SD",12345456648,"XX5","移动电话","非亲属"],
  10.     ["demao","GC",123456,"1","张三","SD",12345456649,"XX6","固定电话","父亲"],
  11.     ["demao","GC",123456,"1","张三","SD",12345456650,"XX7","移动电话","父亲"],
  12.     ["demao","GC",789123,"1","李四","SD",12345456653,"XX10","移动电话","其他亲属"],
  13.     ["demao","GC",789123,"1","李四","SD",12345456654,"XX11","主要手机号码","客户"],
  14.     ["demao","GC",789123,"1","李四","SD",12345456655,"XX12","工作电话","客户"],
  15.     ["demao","GC",789123,"1","李四","SD",12345456656,"XX13","E-mail","客户"],
  16.     ["demao","GC",789123,"1","李四","SD",12345456657,"XX14","固定电话","父亲"],
  17.     ["demao","GC",789123,"1","李四","SD",12345456658,"XX15","验证电话","客户"],
  18.     ["demao","GC",789123,"1","李四","SD",12345456659,"XX16","E-mail","客户"]
  19. ]

  20. my_dic = defaultdict(list)

  21. for i in scro:
  22.     my_dic[tuple(i[:6])] += i[6:]

  23. my_res = [list(k)+v for k, v in my_dic.items()]

  24. print(my_res)
复制代码


TA的精华主题

TA的得分主题

发表于 2019-2-23 07:21 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
小花鹿 发表于 2019-2-22 12:55
Sub test()
Dim d, d1, i&, ar, r&, j&, c&
Set d = CreateObject("scripting.dictionary")

留底精品!!!

TA的精华主题

TA的得分主题

发表于 2019-2-23 09:37 来自手机 | 显示全部楼层
duquancai 发表于 2019-2-22 23:38
只需要4行代码就能搞定》》》》》

这个没有读Excel表的,是不是olefileio这个库要用下

TA的精华主题

TA的得分主题

发表于 2019-2-23 10:08 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
zpy2 发表于 2019-2-23 09:37
这个没有读Excel表的,是不是olefileio这个库要用下

读写Excel就不再赘述!

TA的精华主题

TA的得分主题

发表于 2019-2-23 10:19 来自手机 | 显示全部楼层
duquancai 发表于 2019-2-23 10:08
读写Excel就不再赘述!

我也来一个 sql
字段
机构,model,GROUP_CONCAT(DISTINCT(合同号)),有效合同,客户名,城市,GROUP_CONCAT(电话||'|'||电话所属人||'|'||电话类型||'|'||与客户关系||'|','<br>') as t

分组
机构,model,客户名,城市
Screenshot_2019-02-23-10-17-31.png

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-2-23 13:45 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

谢谢大神。可以用的

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-2-23 13:46 | 显示全部楼层
小花鹿 发表于 2019-2-22 12:55
Sub test()
Dim d, d1, i&, ar, r&, j&, c&
Set d = CreateObject("scripting.dictionary")

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

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-12-27 05:19 , Processed in 0.034426 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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