Get ColumnLetter by ColumnNumber in Excel with VBA
2010-05-12 17:55
387 查看
Function GetColumnLetterByColumnNumber(ColumnNumber As Integer) As String
If ColumnNumber > 26 Then
' 1st character: Subtract 1 to map the characters to 0-25,
' but you don't have to remap back to 1-26
' after the 'Int' operation since columns
' 1-26 have no prefix letter
' 2nd character: Subtract 1 to map the characters to 0-25,
' but then must remap back to 1-26 after
' the 'Mod' operation by adding 1 back in
' (included in the '65')
ColumnLetter = Chr(Int((ColumnNumber - 1) / 26) + 64) & Chr(((ColumnNumber - 1) Mod 26) + 65)
Else
' Columns A-Z
ColumnLetter = Chr(ColumnNumber + 64)
End If
End Function
If ColumnNumber > 26 Then
' 1st character: Subtract 1 to map the characters to 0-25,
' but you don't have to remap back to 1-26
' after the 'Int' operation since columns
' 1-26 have no prefix letter
' 2nd character: Subtract 1 to map the characters to 0-25,
' but then must remap back to 1-26 after
' the 'Mod' operation by adding 1 back in
' (included in the '65')
ColumnLetter = Chr(Int((ColumnNumber - 1) / 26) + 64) & Chr(((ColumnNumber - 1) Mod 26) + 65)
Else
' Columns A-Z
ColumnLetter = Chr(ColumnNumber + 64)
End If
End Function
相关文章推荐
- Get number from string with regular expression in java
- [FUNC]Excel的列名称数字转换成字符convert column number to letter
- Caused by: org.xml.sax.SAXParseException; systemId: file:/home/hadoop/hive-0.12.0/conf/hive-site.xml; lineNumber: 5; columnNumber: 2; The markup in the document following the root element must be well
- [LeetCode By Python]171. Excel Sheet Column Number
- SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql_mode=only_full_group_by
- What Column Number Is It in the EXCEL?
- Read a Text File with VBA in Excel, and Write the Text to a Spreadsheet
- 171. Excel Sheet Column Number
- How to get response content with specified post data by post method
- Find n‘th number in a number system with only 3 and 4
- How to get started with data science in containers
- leetcode 日经贴,Cpp code -Excel Sheet Column Number
- LeetCode-171. Excel Sheet Column Number (Java)
- Excel Sheet Column Number
- 【LeetCode with Python】 Letter Combinations of a Phone Number
- Excel Sheet Column Number
- row_number() over(partition by column1 order by column2)
- LeetCode *** 171. Excel Sheet Column Number
- 11.Excel Sheet Column Number(26进制转化为10进制)
- Excel Sheet Column Number