在VBA

2013-11-23 44 views
0

我在新制作的自動ID,並試圖給出一個自動ID中,我用下面的代碼:在VBA

y = 0 
If txtdsgnation = "Plumbing" Then 
x = "P" 
Do Until Cells(i, 3) = ""   
    If Cells(i, 3) = "Plumbing" Then 
    y = y + 1 
    End If 
    i = i + 1 
Loop 
End If 
If txtdsgnation = "Electricity" Then 
x = "E" 
Do Until Cells(i, 3) = "" 

    If Cells(i, 3) = "Electricity" Then 
    y = y + 1 
    End If 
    i = i + 1 
Loop 
End If 
If txtdsgnation = "Fittings" Then 
x = "F" 
Do Until Cells(i, 3) = "" 

    If Cells(i, 3) = "Fittings" Then 
    y = y + 1 
    End If 
    i = i + 1 
Loop 
End If 
If txtdsgnation = "Lift maintenance" Then 
x = "L" 
Do Until Cells(i, 3) = "" 

    If Cells(i, 3) = "Lift maintenance" Then 
    y = y + 1 
    End If 
    i = i + 1 
Loop 
End If 

z = 100 + y 

txtID = x + "-" + z 

我試圖做的事情是,如果我添加一個新員工,例如一個水管工,我已經有2個管道工txtID會自動變成「P-102」 在此先感謝

+0

應該是:txtID = x +「 - 」+ CStr(z) –

+0

謝謝!工作完美...:D – user3024808

回答

0

在循環中,y總是獲得0初始化。所以,y沒有機會變得更多比1.請儘量讓y離開循環。

+0

奧普斯對不起...但這不是問題是,這兩條線donot工作... z = 100 + y 和 txtID = x +「 - 」+ z – user3024808