找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 499|回复: 0

[原创] [功能]VBE 地址、列号、行号----入门操作

[复制链接]
发表于 2016-11-24 14:18:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
  1. [功能]地址、列号、行号
  2. Sub SelectionAddress()
  3.     '常用的选择方式有selection CurrentRegion UsedRange [a1:e5]
  4.     arr = Range("a2").CurrentRegion
  5.     Range("a2").CurrentRegion.Select '选择对象,但不能arr.Select
  6.     Debug.Print UBound(arr) '行
  7.     Debug.Print UBound(Application.WorksheetFunction.Index(arr, 1, 0)) '多少列 同Selection(Selection.Count).Column
  8.    
  9.     'Debug.Print Selection(1).Value '下同
  10.     Debug.Print arr(1, 1)
  11.    
  12.     MsgBox Selection(1).Row ' 第一个单元格行号
  13.     Debug.Print Cells(Selection(1).Row, Selection(1).Column) '选中单元格中第一个单元格的值,同Selection(1)
  14.    
  15.     Debug.Print Selection(Selection.Count).Row ' 最后一个单元格行号
  16.     Debug.Print Selection(Selection.Count).Column ' 最后一个单元格列号(数值)'多少列
  17.    
  18.     MsgBox Selection.Count '总数量
  19.    
  20.     Debug.Print Selection.Address '地址范围,如$K$2:$L$13
  21.     Debug.Print Split(Selection.Address, "$")(1) '第一对象列号 下同
  22.     Debug.Print Split(Selection(1).Address, "$")(1) '第一对象列号
  23.     Debug.Print Split(Selection(Selection.Count).Address, "$")(1) '最后一个单元格列号
  24.     Debug.Print Split(Selection(Selection.Count).Address, "$")(2) '最后一个单元格行号
  25.    
  26.     Debug.Print Range("A65536").End(xlUp).Row 'A列最后一个单元格行号 下同
  27.     Debug.Print [A65535].End(xlUp).Row ' 下同
  28.     Debug.Print Cells(Rows.Count, 1).End(xlUp).Row '推荐
  29.    
  30.     Cells(Selection(Selection.Count).Row, Selection(Selection.Count).Column).Select '最后一个单元格 被选择到
  31.     Cells(Selection(Selection.Count).Row, Selection(Selection.Count).Column).Offset(1, 0).Select '最后一个单元格的一下单元格 被选择到

  32. End Sub
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-28 12:46 , Processed in 0.162176 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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