I am stuck in Excel VBA code. I want my delete button to check two conditions. If all meet requirements, than delete, otherwise nothing. I have two sheets. One sheet record delete if another sheet have no any record.
Below is my current code. My second sheet name is trial balance. I want if textbox4 value check in second sheet and found and also found any value in front of 4 column, so select entry will not delete other wise delete.
I don't feel my English is very good, so I may not have described things quite the way you are expecting.
Private Sub CommandButton8_Click()
Dim I As Long
Dim W As Worksheet
Dim Z As Long
Dim cDelete As VbMsgBoxResult
Set W = Sheets("Chart of Account")
Z = W.Range("C" & Rows.Count).End(xlUp).Row
For I = 8 To Z
If W.Cells(I, 2).Value = TextBox4.Text Then
cDelete = MsgBox("ARE YOU SURE THAT YOU WANT TO DELETE THIS RECORD", vbYesNo)
If cDelete = vbYes Then
W.Rows(I).Delete Shift:=xlUp
End If
End If
Next I