本文讨论如何使用 Microsoft Excel 中的 Microsoft Visual Basic for Applications (VBA) 功能将同一列中的列号转换为其对应的字母字符指示符。
例如,列号 30 被转换为相应的字母字符“AD”。 使用下列算法可以实现“ConvertToLetter”功能:
1 Function ConvertToLetter(iCol As Integer) As String 注意:此函数仅将传递给它的整数转换为其对应的字母数字文本字符,不改变实际工作表上的列标题或行标题的外观。2 Dim iAlpha As Integer 3 Dim iRemainder As Integer 4 iAlpha = Int(iCol / 27) 5 iRemainder = iCol - (iAlpha * 26) 6 If iAlpha > 0 Then 7 ConvertToLetter = Chr(iAlpha + 64) 8 End If 9 If iRemainder > 0 Then 10 ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64) 11 End If 12 End Function 13 |
|
来自: Excel实用知识 > 《VBA与EXCEL》