在Excel列中获取最后一个非空单元格 [英] Get last non-empty cell in Excel column
问题描述
我尝试了CountA和其他几个,但是它返回非 - 空单元格或假设在实际数据中有一些空格的空格中间有一个单元格,UsedRange返回到该单元格的范围。
我需要什么是列中最后一个非空单元格,该列中可能有空单元格。使用该列中最后一个空单元格,我可以指定要使用的最后一行。
在VBA中,您可以在宏代码上使用这样的东西:
rcount = Range(A:A)。End(xlUp).Row
它将返回给定列上最后一个非空单元格的值
在C#中,您可以尝试:
Excel.Worksheet sh;
long lastRow;
long fullRow;
sh = app.Workbooks.get_Item(Workbook1.xlsx)。Worksheets.get_Item(Sheet1);
fullRow = sh.Rows.Count;
lastRow = sh.Cells [fullRow,1] .get_End(Excel.XlDirection.xlUp).Row;
//使用get_End而不是End
How can we get a number/index of the last empty cell in a column in Excel.
I tried CountA and several others but it returns the count of non-empty cells or suppose there is a cell in the middle of nowhere after actual data with some spaces in that, the UsedRange returns range up to that cell.
What I need is a last non-empty cell in a column where that column may have empty cells in between. Using this last empty cell in that column, I can specify the last row to be considered for use.
In VBA you can use something like this on macro code:
rcount = Range("A:A").End(xlUp).Row
It will return the value of the last non-empty cell on the given column
In C# you can try:
Excel.Worksheet sh;
long lastRow;
long fullRow;
sh = app.Workbooks.get_Item("Workbook1.xlsx").Worksheets.get_Item("Sheet1");
fullRow = sh.Rows.Count;
lastRow = sh.Cells[fullRow, 1].get_End(Excel.XlDirection.xlUp).Row;
//use get_End instead of End
这篇关于在Excel列中获取最后一个非空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!