Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找给定行中最后使用的列-Excel VBA_Excel_Vba - Fatal编程技术网

查找给定行中最后使用的列-Excel VBA

查找给定行中最后使用的列-Excel VBA,excel,vba,Excel,Vba,我必须获取某一行中最后使用的单元格 例如:如果我选择A1,最后使用的列应该返回3 行/上次使用的列 A1/3 A2/4 A3/3 A4/3 A5/1 A6/3 A7/4以下功能已从 来自Chip Pearson的Dan posts功能非常通用。但对于大多数应用程序来说,这可能有点过头了。如果您正在寻找更简单的方法: Sub GetLastColumn() Dim colRange As Range Dim rowNum As Long rowNum = InputBox("Enter the

我必须获取某一行中最后使用的单元格

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

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

以下功能已从


来自Chip Pearson的Dan posts功能非常通用。但对于大多数应用程序来说,这可能有点过头了。如果您正在寻找更简单的方法:

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

可能的重复为什么要把这么简单的事情弄得这么复杂。参考下面的David答案。最好使用
列。计数
而不是16384。@Santosh为真,尤其是向后兼容。我已经修改了。@YowE3K没有测试它,不,我不认为
Range.End
方法就是这样工作的。@YowE3K我想我在试图回答一个4年多的答案时弄糊涂了:如果我只做
Set colRange=Cells(rowNum,Columns.Count)。End(xlToLeft)
那么结果是正确的D4。很好-现在我有一个问题要用作dup目标。现在我只需要再次找到我将要使用它的问题:D
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