ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 763|回复: 8

[求助] 如何取某列的相同数据只显示一次?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-10-15 20:30 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
附件里有说明。
[40$2WC5HYYY(3DQPJ5{[WJ.png

表格1015.zip

30.44 KB, 下载次数: 5

TA的精华主题

TA的得分主题

发表于 2019-10-15 20:53 来自手机 | 显示全部楼层
等老师们现身解决,俺也有相似的需求

TA的精华主题

TA的得分主题

发表于 2019-10-15 20:54 | 显示全部楼层
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = True
    Set d = CreateObject("scripting.dictionary")
    If Target.Column = 7 And Target.Row > 7 And Target.Row < 17 Then
        'If Sheet1.ProtectContents Then Sheet1.Unprotect Password:="1111"
        If Range("G8") <> "" Then a = Sheet1.Range("D8"): d(a) = ""
        For i = 8 To 16
            If Sheet1.Cells(i, "G") = "" Then a = a & "→" & Sheet1.Cells(i - 1, "G"): Exit For
            If Not d.exists(Sheet1.Cells(i, "G").Value) Then
                d(Sheet1.Cells(i, "G").Value) = ""
                a = a & "→" & Sheet1.Cells(i, "G")
            End If
        Next
        Range("G32") = a
        'Sheet1.Protect Password:="1111", DrawingObjects:=1, Contents:=1, Scenarios:=1
        Application.ScreenUpdating = True
    End If
End Sub
上面的代码是根据最后一个城市跟第一个城市一致来处理的

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-10-15 21:06 | 显示全部楼层
本帖最后由 环境所迫 于 2019-10-15 21:08 编辑
liulang0808 发表于 2019-10-15 20:54
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = True
    Set  ...

老师你好,谢谢,但现是有点问题,就是都是空白的话,显示的是“→终点”,G列如果有内容的话,最后一个是重复显示的
567.gif

TA的精华主题

TA的得分主题

发表于 2019-10-15 21:11 | 显示全部楼层
If Sheet1.Cells(i, "G") = "" Then a = a & "→" & Sheet1.Cells(i - 1, "G"): Exit For
修改如下看看
If Sheet1.Cells(i, "G") = "" Then
if len(a)>0 then a = a & "→" & Sheet1.Cells(i - 1, "G"):
Exit For
endif

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-10-15 21:15 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
liulang0808 发表于 2019-10-15 21:11
If Sheet1.Cells(i, "G") = "" Then a = a & "→" & Sheet1.Cells(i - 1, "G"): Exit For
修改如下看看
I ...

都没有内容的问题解决了,可G列有内容的话,最后一个还是重复显示的

TA的精华主题

TA的得分主题

发表于 2019-10-15 21:42 | 显示全部楼层

If Sheet1.Cells(i, "G") = "" Then a = a & "→" & Sheet1.Cells(i - 1, "G"): Exit For
修改如下看看
If Sheet1.Cells(i, "G") = "" Then
if len(a)>0 then a = a & "→" & Sheet1.Cells(i - 1, "G")'这段是增加最后一个重复项,如果不需要,就取消吧
Exit For
endif

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-10-15 21:55 | 显示全部楼层
liulang0808 发表于 2019-10-15 21:42
If Sheet1.Cells(i, "G") = "" Then a = a & "→" & Sheet1.Cells(i - 1, "G"): Exit For
修改如下看看
...

您好,现在基本上可以了,就是如果在G列中间有和起点一样地名的话,没有取出显示

TA的精华主题

TA的得分主题

发表于 2019-10-15 22:02 | 显示全部楼层
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Application.ScreenUpdating = True

  3.     If Target.Column = 7 And Target.Row > 7 And Target.Row < 17 Then
  4.         'If Sheet1.ProtectContents Then Sheet1.Unprotect Password:="1111"
  5.         If Range("G8") <> "" Then a = Sheet1.Range("D8"): str1 = a
  6.         For i = 8 To 16
  7.             If Sheet1.Cells(i, "G") = "" Then
  8.                  Exit For
  9.             End If
  10.             If str1 <> Sheet1.Cells(i, "G").Value Then
  11.                 str1 = Sheet1.Cells(i, "G").Value
  12.                 a = a & "→" & Sheet1.Cells(i, "G")
  13.             End If
  14.         Next
  15.         Range("G32") = a
  16.         'Sheet1.Protect Password:="1111", DrawingObjects:=1, Contents:=1, Scenarios:=1
  17.         Application.ScreenUpdating = True
  18.     End If
  19. End Sub
复制代码

之前理解有出入,这次看看吧

评分

1

查看全部评分

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

本版积分规则

关闭

最新热点上一条 /1 下一条

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

GMT+8, 2024-4-26 20:32 , Processed in 0.043699 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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