|
楼主 |
发表于 2017-3-14 21:48
|
显示全部楼层
'################################################################
'6.函数作用:按SplitType取得RangeName串值中的起始位置
'################################################################
'1:单元格,2:行号,3:列号,4:范围
Public Const SINGLE_CELL = 1
Public Const ROW_NUM = 2
Public Const COL_NUM = 3
Public Const RANGE_ALL = 4
Public Function SplitRangeName(RangeName As String, SplitType As Integer) As String
If VBA.Len(RangeName) < 3 Then
Exit Function
Else
RangeName = VBA.Right(RangeName, VBA.Len(RangeName) - VBA.InStr(1, RangeName, "!") - 1)
If VBA.InStr(1, RangeName, ":") > 0 Then RangeName = VBA.Left(RangeName, VBA.InStr(1, RangeName, ":") - 1)
Select Case SplitType
Case SINGLE_CELL
If VBA.InStr(1, RangeName, ":") <> 0 Then
SplitRangeName = "$" & VBA.Left(RangeName, VBA.InStr(1, RangeName, ":") - 1)
Else
SplitRangeName = "$" & RangeName
End If
Case ROW_NUM
SplitRangeName = VBA.IIf(VBA.InStr(1, RangeName, "$") > 0, VBA.Right(RangeName, VBA.Len(RangeName) - VBA.InStr(1, RangeName, "$")), RangeName)
If Not IsNumeric(SplitRangeName) Then
SplitRangeName = ""
MsgBox "", vbInformation, ""
End If
Case COL_NUM
If VBA.InStr(1, RangeName, "$") > 0 Then
SplitRangeName = VBA.Left(RangeName, VBA.InStr(1, RangeName, "$") - 1)
Else
SplitRangeName = RangeName
End If
If IsNumeric(SplitRangeName) Then
SplitRangeName = ""
MsgBox "", vbInformation, ""
End If
Case RANGE_ALL
SplitRangeName = "$" & RangeName
End Select
End If
End Function |
|