mahmoudnasr2000
New Member
>>> use code - tags <<<
Code:
Sub Cod_Sereal_Number()
On Error Resume Next
Set ww = Application.WorksheetFunction
ThisWorkbook.Activate
Dim old_name, new_name
old_name = Me.ComboBox1.Value
new_name = Me.TextBox1.Value
fda = ww.CountIf(Sheet2.Range("b2:b2000"), old_name)
If fda <= 0 Then: MsgBox "The invoice type is not found in the database. Please enter serial number ( 1 )"
': UserForm1.TextBox1 = 1
Dim ws2 As Worksheet
Set ws2 = Sheets("Data")
Dim lastrow As Long
lastrow = ws2.Cells(ws2.Rows.Count, "a").End(xlUp).Row
Dim i As Integer
Dim foundValue As String
TextBox1.Value = ""
For i = 2 To lastrow
If ws2.Cells(i, 2).Value = ComboBox1.Value Then
foundValue = ws2.Cells(i, 1).Value
End If
Next i
TextBox1.Value = foundValue + 1
Exit Sub
UserForm1.TextBox1 = 1
End Sub
Last edited by a moderator: