EXCEL分析数值宏

分析诸如
254/6/4
258/6/2
257/2/3
256/2/2
255/4/5
257/2/0
256/1/2
256/1/1
252/1/5
成  数值1 数值2  数值3
到相应的列

//////////////////////////////////宏////////////////////////////////////
Sub splitstr()'输入列号如B,输入开始行号,输入结束行号

    Dim str1 As String
    str1 = "246/9/6"
   
   
    startaphla = InputBox("输入开始行字母如 B", "", "B")
   
    startnum = InputBox("输入开始行数字如 3", "", "3")
    endnum = InputBox("输入结束行数字如 17", "", "17")
   
    If (startnum <> "" And endnum <> "" & startaphla <> "") Then
   
    For i = startnum To endnum

    str1 = Range(startaphla & i).Value
   
   ' MsgBox startaphla & i
    If InStr(str1, "/") > 0 Then
        str1_1 = Left(str1, InStr(str1, "/") - 1)
       
        str1 = Right(str1, Len(str1) - InStr(str1, "/"))
       
        str1_2 = Left(str1, InStr(str1, "/") - 1)
       
        str1 = Right(str1, Len(str1) - InStr(str1, "/"))
       
        str1_3 = str1
   
    End If
   
    Range(Chr(Asc(startaphla)) & i).Value = str1_1
    Range(Chr(Asc(startaphla) + 1) & i).Value = str1_2
    Range(Chr(Asc(startaphla) + 2) & i).Value = str1_3
   
    'MsgBox str1_1 & " " & " " & str1_2 & " " & str1_3
    Next i
    End If
   
End Sub

Sub splitstrex()'调用前 先选中开始分析的首个单元格,   输入结束行数字即可
    Dim str1 As String
    str1 = "246/9/6"
   
    
    startaphla = Chr(Selection.Column + 64)
   
    startnum = Selection.Row
    endnum = InputBox("输入结束行数字如 17", "", "17")
   
    If (startnum <> "" And endnum <> "" & startaphla <> "") Then
   
    For i = startnum To endnum

    str1 = Range(startaphla & i).Value
   
   ' MsgBox startaphla & i
    If InStr(str1, "/") > 0 Then
        str1_1 = Left(str1, InStr(str1, "/") - 1)
       
        str1 = Right(str1, Len(str1) - InStr(str1, "/"))
       
        str1_2 = Left(str1, InStr(str1, "/") - 1)
       
        str1 = Right(str1, Len(str1) - InStr(str1, "/"))
       
        str1_3 = str1
   
    End If
   
    Range(Chr(Asc(startaphla)) & i).Value = str1_1
    Range(Chr(Asc(startaphla) + 1) & i).Value = str1_2
    Range(Chr(Asc(startaphla) + 2) & i).Value = str1_3
   
    'MsgBox str1_1 & " " & " " & str1_2 & " " & str1_3
    Next i
    End If
End Sub

posted on 2004-07-30 13:44  DiviSoft  阅读(477)  评论(0编辑  收藏  举报

导航