hello
i need help about add message if the sheet isn't existed the code asks me when i add the data which sheet sometimes i make mistake the name should warn me is wrong not existed this sheet i try add this line but the code doesn't work very well it
orginal code
Code
Private Sub CommandButton1_Click()
whichsheet = InputBox("in which sheet do you wish enter data ? specify sheet number as sheet1,sheet2 & sheet3 only .", "sheet number")
If whichsheet = "" Then
MsgBox "you didn't specify a sheet !"
Exit Sub
End If
Worksheets(whichsheet).Activate
Dim lastrow
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastrow = lastrow + 1
Cells(lastrow, 1) = Me.TextBox1
If Application.WorksheetFunction.CountIf(Range("a2:a" & lastrow), Cells(lastrow, 1)) > 1 Then
MsgBox "duplicated data ! only unique ids allowed", vbCritical, "remove data"
Cells(lastrow, 1) = ""
ElseIf Application.WorksheetFunction.CountIf(Range("a2:a" & lastrow), Cells(lastrow, 1)) = 1 Then
answer = MsgBox("are you sure want to add the record?", vbYesNo + vbQuestion, "add recor")
If answer = vbYes Then
Cells(lastrow, 1) = Me.TextBox1
Cells(lastrow, 2) = Me.TextBox2
Cells(lastrow, 3) = Me.TextBox3
Cells(lastrow, 4) = Me.TextBox4
Cells(lastrow, 5) = Me.TextBox5
End If
End If
End Sub
Display More