|
- Function SSLJ(rgData As Range, Optional LineType As Variant = "", Optional DispLocation As Variant = "") As Variant
- Dim rgFormula As Range '公式所在区域
- Dim arrData As Variant, strResult() As String
- Dim lngRows As Long, lngCols As Long
- Dim lngR As Long, lngC As Long
- Dim strTemp As String, strLast As String
- Dim lngLen As Long, lngMod As Long
- Dim arrTemp As Variant, lngIndex As Long
- Dim lngLineType As Long, lngDispLocation As Long
-
-
-
- Set rgFormula = Application.Caller
- lngRows = rgFormula.Rows.Count
- lngCols = rgFormula.Columns.Count
- ReDim strResult(1 To lngRows, 1 To lngCols) As String
-
- If LineType = "" Then
- lngLineType = 0
- Else
- lngLineType = Val(LineType)
- End If
-
- If DispLocation = "" Then
- lngDispLocation = 0
- Else
- lngDispLocation = Val(DispLocation) - rgFormula.Row + 1
- End If
-
-
- If rgData.Rows.Count < 3 Then Exit Function '如果不足3行,直接退出
-
- arrData = rgData
- arrData = Application.WorksheetFunction.Transpose(arrData)
- strTemp = Join(arrData, ""): strTemp = Replace(strTemp, Space(1), "")
- lngLen = Len(strTemp)
- strLast = Mid(strTemp, lngLen - 1): strTemp = Mid(strTemp, 1, lngLen - 2)
- lngLen = lngLen - 2: lngMod = lngLen Mod 3: lngLen = lngLen \ 3
- strTemp = Mid(strTemp, lngMod + 1)
-
- ReDim arrTemp(1 To lngLen)
- For lngMod = 1 To lngLen
- arrTemp(lngMod) = Mid(strTemp, 1 + (lngMod - 1) * 3, 3)
- Next
-
- If lngDispLocation < 0 Then lngDispLocation = UBound(arrTemp)
- lngMod = lngDispLocation - lngLen
- lngLen = lngDispLocation - UBound(arrTemp) + 1
- If lngLen < 1 Then lngLen = 1
-
- For lngIndex = lngDispLocation To lngLen Step -1
- strResult(lngIndex, 1) = arrTemp(lngIndex - lngMod)
- Next
-
- If lngLineType <> 0 Then strResult(lngDispLocation + 1, 1) = strLast
-
- SSLJ = strResult
- End Function
复制代码 |
|