excel VBA返回选中单元格区域的行数、列数,以及活动单元格的行号和列号


Private Sub Worksheet_SelectionChange(ByVal Target As Range) '可以直接sub(),不然选择就会触发vba
    Dim rows_count As Integer
    Dim rows_id As Integer
    Dim column_count As Integer
    Dim column_id As Integer
    column_count = Selection.Columns.Count '返回选择区域列数
    rows_id = ActiveCell.Row  '返回活动单元格的行号
    rows_count = Selection.Rows.Count  '返回选择区域的行数

    column_id = ActiveCell.Column  '返回活动单元格的列号
    MsgBox rows_count
    MsgBox column_count
    MsgBox column_id
    MsgBox rows_id
End Sub

 




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM