如何使我的macros超出列z – lastcolumnmacros

Function lastrow(colName As String) Dim sht As Worksheet Set sht = ThisWorkbook.ActiveSheet lastrow = sht.Cells(sht.Rows.Count, colName).End(xlUp).Row End Function Function LastCol(rowName As Double) Dim sht As Worksheet Set sht = ThisWorkbook.ActiveSheet LastCol = sht.Cells(rowName, sht.Columns.Count).End(xlToLeft).Column End Function Function lastcell() Dim sht As Worksheet Dim lastrow As Long, lastcolumn As Long Dim lastletter As String Set sht = ThisWorkbook.ActiveSheet lastrow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row lastcolumn = sht.UsedRange.Columns(sht.UsedRange.Columns.Count).Column lastletter = Chr(64 + lastcolumn) lastcell = lastletter & lastrow End Function 

我怎样才能得到最后一个字母行为列AA,AAA,AAAA等工作,因为我的例程使用CHR黑客,但只适用于工作表AZ。

使用Cells()的Address函数:

 lastcell = sht.Cells(lastrow,lastcolumn).Address(0,0) 

我使用函数来查找将数字列转换为其alpha等效

 Dim mycol as string mycol = WColNm(Mycell.Column) ' mycell.column is numeric. Function returns integer Public Function WColNm(ColNum) as string WColNm = Split(Cells(1, ColNum).Address, "$")(1) End Function 

或列数字字母

 Dim IntCol as integer Intcol = WcolNum(“A”) Public Function wcolNum(ColNm) as int wcolNum = Range(ColNm & 1).Column End Function