Hello Again,
I am trying to add data from user form but i have issue while adding serial number in column A. VBA Macros showing error "Run-time error '13'. When i debug it is showing error on highlighted in red color on below code. Can anyone help me please.
Showing Error In Line:
Cells(lNextRow, "A").Value = Cells(lNextRow - 1, "A").Value + 1
Full Code:
Private Sub CommandButton1_Click()
Dim mystr, mytime
Dim diff As Double
Dim LastRow As Long
Dim iRow As Long
Dim rng As Range
Dim ws As Worksheet
Dim lNextRow As Long
'Worksheets("Master Sheet").Unprotect "***"
LastRow = Range("A65536").End(xlUp).Row + 1
mystr = Format("mm/dd/yyyy")
mytime = Format("h:mm")
mytime1 = TimeValue(TextBox4.Value)
mytime2 = TimeValue(TextBox6.Value)
Worksheets("Master Sheet").Select
With Worksheets("Master Sheet")
Set ws = Worksheets("Master Sheet")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'get all the database entires
Set rng = ws.Range("B2", ws.Cells(iRow, "B"))
'Check if part exits in database
If Not rng.find(TextBox1, , xlValues, xlWhole, xlByRows, xlPrevious, False) Is Nothing Then
response = MsgBox("Visa No. '" & TextBox1 & " 'already exits in database" _
+ vbCrLf + " " + vbCrLf + " - Lets Make Life Easier...", _
vbOKOnly + vbInformation, "Approval Entery (Date Format Issue)")
Exit Sub
End If
lNextRow = Cells(Rows.Count, "a").End(xlUp).Row + 1
Cells(lNextRow, "A").Value = Cells(lNextRow - 1, "A").Value + 1
If TextBox1.Text <> "" Then
.Range("B" & LastRow).Value = TextBox1.Text
Else
response = MsgBox("Cannot save data without VISA No." _
+ vbCrLf + " " + vbCrLf + " - Lets Make Life Easier...", _
vbOKOnly + vbInformation, "Approval Entery (Date Format Issue)")
TextBox1.SetFocus
Exit Sub
End If
If CheckBox1.Value = True Then
.Range("C" & LastRow).Value = TextBox10.Text
End If
If CheckBox2.Value = True Then
.Range("C" & LastRow).Value = TextBox10.Text
End If
If CheckBox3.Value = True Then
.Range("C" & LastRow).Value = TextBox10.Text
End If
If CheckBox4.Value = True Then
.Range("C" & LastRow).Value = TextBox10.Text
End If
If CheckBox5.Value = True Then
.Range("C" & LastRow).Value = TextBox10.Text
End If
If CheckBox6.Value = True Then
.Range("C" & LastRow).Value = TextBox10.Text
End If
.Range("D" & LastRow).Value = ComboBox1.Text
.Range("E" & LastRow).Value = TextBox2.Text
.Range("F" & LastRow).Value = Format(TextBox3.Text, mystr)
.Range("G" & LastRow).Value = Format(TextBox4.Text, mytime)
.Range("H" & LastRow).Value = Format(TextBox5.Text, mystr)
.Range("I" & LastRow).Value = Format(TextBox6.Text, mytime)
.Range("L" & LastRow).Value = TextBox7.Text
.Range("M" & LastRow).Value = ComboBox2.Text
dif = CDate(TextBox5.Value) - CDate(TextBox3.Value)
TextBox8.Text = dif
.Range("J" & LastRow).Value = TextBox8.Text
mytime3 = mytime2 - mytime1
TextBox9.Value = Format(mytime3, "hh:mm")
.Range("K" & LastRow).Value = Format(TextBox9.Text, mytime)
response = MsgBox("Record has been entered into sheet " & "'" & UCase(ActiveSheet.Name) & "'" & " successfully" _
+ vbCrLf + " " + vbCrLf + " - Lets Make Life Easier...", _
vbOKOnly + vbInformation, "Approval Entery (Date Format Issue)")
'Worksheets("Master Sheet").Protect "***"
End With
End Sub
Bookmarks