2013-05-14 51 views
0

我希望削減從右側兩個單元兩個數字,在什麼點數量相等查找和打印的另一個小區的數量在圖片說明削減在Excel中一些如何根據病情

enter image description here

任何一個請幫我

回答

2

你沒有實際比較兩個數字,它們是字符串(因爲你有一個前導零)。您可以使用Left功能輕鬆完成此操作。

enter image description here

而這裏顯示的公式同樣的事情:

enter image description here

或者你也可以在VBA做到這一點:

Public Function CompareTwoNumbers(num1 As String, num2 As String) As String 

Dim i As Long 
Dim temp1 As String, temp2 As String 

For i = Len(num1) To 1 Step -1 

    temp1 = Left(num1, i) 
    temp2 = Left(num2, i) 

    If temp1 = temp2 Then 
     CompareTwoNumbers = temp1 
     Exit Function 
    End If 

Next 

CompareTwoNumbers = "The numbers do not match" 

End Function 
+0

喜史蒂夫例子是完美的,但我需要一個當你的例子0785中的第一次條件變爲true時,更多的事情是,值0785必須打印在另一個單元格中,是否有可能? – 2013-05-14 09:10:57

+0

您可以使用Len函數來計算結果的長度(即0785 = 4)。然後你會有0785和4作爲你的答案。你是這個意思嗎? – steveo40 2013-05-14 10:37:45