找出给定行中最后使用的列-Excel VBA [英] Find out the last used column in a given row - Excel VBA

查看:85
本文介绍了找出给定行中最后使用的列-Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须获取特定行中最后使用的单元格.

I have to get the last used cell in a particular row.

例如:如果我选择A1,则最后使用的列应返回3.

For example: If I choose A1 the last used column should return 3.

行/最后使用的列 A1/3 A2/4 A3/3 A4/3 A5/1 A6/3 A7/4

Row/LastUsedColumn A1/ 3 A2 / 4 A3 / 3 A4 / 3 A5 / 1 A6 / 3 A7 / 4

推荐答案

Dan从Chip Pearson发表的功能超级通用.但是,对于大多数应用程序来说,可能会显得过分杀伤力.如果您正在寻找更简单的方法:

The function Dan posts from Chip Pearson is super versatile. But probably overkill for most applications. If you're looking for something simpler:

Sub GetLastColumn()
Dim colRange As Range
Dim rowNum As Long

rowNum = InputBox("Enter the row number")

Set colRange = Cells(rowNum, Columns.Count).End(xlToLeft)
lastCol = colRange.Column

MsgBox colRange.Address

End Sub

这篇关于找出给定行中最后使用的列-Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆