firstcolumn最终select

我试图编写一个子程序捕获第一个单元格,第一列,并select数据到最后一行,最后一列的值。 我想在其他子程序中调用和引用这个子。 我正在寻找一种有效的编码方法。

我花了时间与这两个答案:

如何select拉斯特罗

Sub SelectLastRow() Dim nRow As Long, nColumn As Long nRow = Cells(Rows.Count, "A").End(xlUp).Row nColumn = Cells(nRow, Columns.Count).End(xlToLeft).Column Range(Cells(nRow, "A"), Cells(nRow, nColumn)).Select End Sub 

我有兴趣扭转更高的投票答案在这里: Excel VBAselect范围在最后一行和一列

这里是一个数据集,我只想用头来捕获整个select。

 Fail Count 2 90 1 58 

编辑:

我只是发现这个代码,这是什么我想要的,什么是.SpecialCells(xlCellTypeConstants, 23)

 Dim LR As Long LR = Range("A" & Rows.Count).End(xlUp).Row Range("a1:G" & LR).SpecialCells(xlCellTypeConstants, 23).Select 

 Public Function DataRange(Somesheet as String, Optional StartCell as String) as Excel.Range If StartCell = "" Then DataRange =ThisWorkbook.Sheets( Somesheet).Range( ThisWorkbook.Sheets( Somesheet)_ .Cells(1,1).End(xldown),ThisWorkbook.Sheets(Somesheet).Cells(1,1).End(xlright)) Else DataRange = ThisWorkbook.Sheets(Somesheet).Range(ThisWorkbook.Sheets(Somesheet)_ .Range(Startcell).End(xldown),ThisWorkbook.Sheets(Somesheet).Range(Startcell).End(xlright)) End If End Function 

如果你放入一个单元格引用,它将返回该单元格的数据范围。

.SpecialCells(xlCellTypeConstants,23)的意义是什么?

这是默认参数,可以省略:

 XlSpecialCellsValue constants Value xlErrors 16 xlLogical 4 xlNumbers 1 xlTextValues 2