- '将 A 转成 1
- Function ConvertExcelNumToInt(colName As String) As Integer
- Dim i As Integer
- Dim rtn As Integer
- If Len(colName) = 0 Then
- ConvertExcelNumToInt = 0
- Exit Function
- End If
- colName = UCase(colName)
- rtn = 0
- For i = 1 To Len(colName)
- rtn = rtn * 26
- rtn = rtn + Asc(Mid(colName, i, 1)) - 64
- Next
- ConvertExcelNumToInt = rtn
- End Function
- '将 1 转成 A
- Function ConvertToLetter(iCol As Integer) As String
- Dim iAlpha As Integer
- Dim iRemainder As Integer
- iAlpha = Fix(iCol / 26)
- iRemainder = iCol - (iAlpha * 26)
- If iAlpha > 0 Then
- If iRemainder = 0 Then
- iAlpha = iAlpha - 1
- iRemainder = 26
- End If
- If (iAlpha > 0) Then
- ConvertToLetter = Chr(iAlpha + 64)
- End If
- End If
- If iRemainder > 0 Then
- ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
- End If
- End Function
- '取得AutoFilter的行号列表
- Function GetAutoFilterResult(sh As Worksheet) As VBA.Collection
- Dim rtn As New VBA.Collection
- Dim curCell As Range
- countchange = WorksheetFunction.Subtotal(3, sh.AutoFilter.Range)
- If (countchange = sh.AutoFilter.Range.Columns.Count) Then
- Exit Function
- End If
- Set curCell = sh.Cells(sh.AutoFilter.Range.Row + 1, 1)
- While Not IsEmpty(curCell) ' Check to see if row
- ' height is zero.
- If curCell.RowHeight > 0 Then
- rtn.Add (curCell.Row)
- End If
- Set curCell = curCell.Offset(1, 0)
- Wend
- Set GetAutoFilterResult = rtn
- End Function
- '记事..
- Sub dictionarySample()
- Dim dic ' As New Dictionary
- Dim d As New VBA.Collection
- d.Add ("1")
- d.Remove (1)
- Set dic = CreateObject("scripting.dictionary")
- dic.Add "key", "Dictionary"
- s = dic.Item("key")
- 'Add(key,item) 增加键/条目对到 Dictionary
- 'Exists (key) 如果指定的键存在,返回 True,否则返回 False
- 'Items() 返回一个包含 Dictionary 对象中所有条目的数组
- 'Keys() 返回一个包含 Dictionary 对象中所有键的数组
- 'Remove (key) 删除一个指定的键/条目对
- 'RemoveAll() 删除全部键/条目对
- End Sub