2017-02-18 88 views
0

我需要做的是基本寫入課程編號。有3個colomns。 enter image description hereExcel如果單元格中包含「 - 」數字然後移動

第二列由被稱爲LessonsLeft自定義公式被人從我的計算器第二個線程運行完,它是

Function LessonsLeft(rng As Range) As String 
If rng.Count > 1 Then Exit Function 
Dim spltStr() As String 
Dim i As Long 
spltStr = Split(rng.Value, ",") 
LessonsLeft = ",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50," 
For i = LBound(spltStr) To UBound(spltStr) 
    LessonsLeft = Replace(LessonsLeft, "," & spltStr(i) & ",", ",") 
Next i 
LessonsLeft = Mid(LessonsLeft, 2, Len(LessonsLeft) - 2) 
End Function 

我需要做的是添加另一個,第三colomn這是對於我的學生第一次嘗試但他們無法通過考試的課程。

我想要數據如何存在,是在第一列的數字附近編寫例如「 - 」或「+」,以便數字移至第三列。

怎麼辦?

+0

我的意思是,如果爲例i的第一列「5」寫了5將出現在第三個 –

回答

2

使用此功能

Function LessonsAttemptedButNotDone(rng As Range) As String 
    If rng.Count > 1 Then Exit Function 
    Dim spltStr() As String, lessonDone As String 
    Dim i As Long 

    spltStr = Split(rng.Value, ",") 
    For i = LBound(spltStr) To UBound(spltStr) 
     lessonDone = spltStr(i) 
     If Right(lessonDone, 1) = "-" Then 
      lessonDone = Left(lessonDone, Len(lessonDone) - 1) 
      LessonsAttemptedButNotDone = LessonsAttemptedButNotDone & lessonDone & "," 
     End If 
    Next 
    If LessonsAttemptedButNotDone <> "" Then LessonsAttemptedButNotDone = Left(LessonsAttemptedButNotDone, Len(LessonsAttemptedButNotDone) - 1) 
End Function 
+0

這是做的工作。謝謝 –

+0

不客氣 – user3598756

相關問題