如何使我的宏工作超出列z - lastcolumn宏

时间:2017-09-05 13:57:50

标签: excel vba function

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 hack,但仅适用于A-Z表。

2 个答案:

答案 0 :(得分:1)

使用Cells()的地址功能:

def update_ego(self):
    if self.ego < 100:
        self.ego += 1

答案 1 :(得分: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