ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] 创建按第二参数指定的位置开始,向上或向下显示数据源非空数据的自定义函数

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-9-26 16:52 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖最后由 玉阳山人 于 2019-9-27 16:07 编辑

1.gif

从指定位置开始,显示所有非空数据.zip (8.44 KB, 下载次数: 7)

请老师们帮忙写个能够嵌套其它函数的自定义函数。每行代码后面最好加上详细说明。

TA的精华主题

TA的得分主题

发表于 2019-9-26 17:06 | 显示全部楼层
你为何不直接找lsdongjh做你专门代工?联系不上吗?

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-9-26 19:43 | 显示全部楼层
请老师们帮忙写个自定义函数。每行代码后面最好加上详细说明。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-9-26 23:50 | 显示全部楼层
请老师们帮忙写个自定义函数。每行代码后面最好加上详细说明。以便深入学习和掌握不同指定条件下数据显示位置的思路。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-9-27 09:19 | 显示全部楼层
请老师们帮忙写个自定义函数。每行代码后面最好加上详细说明。以便深入学习和掌握不同指定条件下数据显示位置的诀窍方法。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-9-27 13:57 | 显示全部楼层
请老师们帮忙写个自定义函数。每行代码后面最好加上详细说明。以便深入学习和掌握不同指定条件下数据显示位置的诀窍方法。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-9-27 16:07 | 显示全部楼层
请老师们帮忙写个自定义函数。每行代码后面最好加上详细说明。以便深入学习和掌握不同指定条件下数据显示位置的诀窍方法。

TA的精华主题

TA的得分主题

发表于 2019-9-27 17:42 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
  1. Option Explicit

  2. Function SJTJTQ(rgSource As Range, lngStartRowID As Long) As Variant
  3.     Dim arrSource As Variant, arrResult As Variant, lngRow As Long
  4.     Dim rgCaller As Range, lngStartID As Long, lngMax As Long, lngEnd As Long
  5.     Dim strContent As String, strSplit() As String, lngStep As Long
  6.    
  7.     Set rgCaller = Application.Caller
  8.     lngMax = rgCaller.Rows.Count '公式所在的总行数
  9.     ReDim arrResult(1 To lngMax, 1 To 1) As String
  10.    
  11.     If rgSource.Columns.Count > 1 Then
  12.         arrResult(1, 1) = "数据区域只能是1列!"
  13.         SJTJTQ = arrResult
  14.         Exit Function
  15.     End If
  16.    
  17.     If rgSource.Rows.Count > lngMax Then
  18.         arrResult(1, 1) = "公式区域小于数据区域!"
  19.         SJTJTQ = arrResult
  20.         Exit Function
  21.     End If
  22.    
  23.     If rgSource(1).Row <> rgCaller(1).Row Then
  24.         arrResult(1, 1) = "公式与数据首行不对应!"
  25.         SJTJTQ = arrResult
  26.         Exit Function
  27.     End If
  28.    
  29.     If lngStartRowID < 1 Then
  30.         arrResult(1, 1) = "指定行号错误"
  31.         SJTJTQ = arrResult
  32.         Exit Function
  33.     End If
  34.     If lngStartRowID > 2 Then
  35.         If lngStartRowID < rgSource(1).Row Or lngStartRowID > rgSource(1).Row + rgSource.Rows.Count - 1 Then
  36.             arrResult(1, 1) = "指定行号错误"
  37.             SJTJTQ = arrResult
  38.             Exit Function
  39.         End If
  40.     End If
  41.    
  42.     Set rgCaller = Nothing
  43.    
  44.     '判断数据的起始、结束行号
  45.     lngRow = rgSource(1).Row - 1
  46.     If Trim(rgSource(1).Value) <> "" Then
  47.         lngStartID = 1
  48.     Else
  49.         Set rgCaller = rgSource.Find("*", LookIn:=xlValues)
  50.         If rgCaller Is Nothing Then
  51.             arrResult(1, 1) = "无数据!"
  52.             SJTJTQ = arrResult
  53.             Exit Function
  54.         End If
  55.         lngStartID = rgSource.Find("*", LookIn:=xlValues).Row - lngRow
  56.     End If
  57.     lngEnd = rgSource.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row - lngRow
  58.    
  59.     arrSource = rgSource
  60.     arrSource = Application.WorksheetFunction.Transpose(arrSource)
  61.     strContent = Application.WorksheetFunction.Trim(Join(arrSource, Space(1)))
  62.     strSplit = Split(strContent, Space(1))
  63.    
  64.     Select Case lngStartRowID
  65.         Case 1 '顺排
  66.             For lngRow = LBound(strSplit) To UBound(strSplit)
  67.                 arrResult(lngRow + lngStartID, 1) = strSplit(lngRow)
  68.             Next
  69.         Case 2 '逆排
  70.             For lngRow = UBound(strSplit) To LBound(strSplit) Step -1
  71.                 arrResult(lngEnd, 1) = strSplit(lngRow)
  72.                 lngEnd = lngEnd - 1
  73.             Next
  74.         Case Else '指定行号逆排
  75.             lngStartRowID = lngStartRowID - rgSource(1).Row + 1
  76.             For lngRow = UBound(strSplit) To LBound(strSplit) Step -1
  77.                 arrResult(lngStartRowID, 1) = strSplit(lngRow)
  78.                 lngStartRowID = lngStartRowID - 1
  79.                 If lngStartRowID = 0 Then Exit For
  80.             Next
  81.     End Select
  82.    
  83.     SJTJTQ = arrResult
  84. End Function
复制代码

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2019-9-27 17:50 | 显示全部楼层

你提供个联系方式给道长啊,叫他直接找你啊,这样不用一天天的不停的自顶贴,等你的回复

TA的精华主题

TA的得分主题

发表于 2019-9-27 17:53 来自手机 | 显示全部楼层
microyip 发表于 2019-9-27 17:50
你提供个联系方式给道长啊,叫他直接找你啊,这样不用一天天的不停的自顶贴,等你的回复

权当练习了

评分

1

查看全部评分

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

本版积分规则

关闭

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

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

GMT+8, 2024-4-23 17:04 , Processed in 0.048103 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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