I have a USERForm with a LISTBOX displaying data from a WORKSHEET called "ANALYSISDB", The UserForm is initiated from a WORKSHEET called "PLOT", Through a Macro. On the UserForm there are command buttons to Save, Search, Update and Delete data from the ANALYSISDB sheet. All commands work correctly, APART FROM the delete command. The Data is selected by a Double Click on a row in the ListBox. When The DELETE command is run, a row from the PLOT sheet and not the ANALYSIDB sheet is deleted, it does however selected the correct row number, but from the wrong sheet. How do I ensure the delete command works on the ANALYSISDB sheet, do I need code to force the entire UserForm to refer to the ANALYSISDB sheet, and what is this code. The Code for the Delete command button is below. My VBA skills are limited so any help would be appreciated.
Private Sub cmd_Delete_Click()
Dim x As Long
Dim Y As Long
x = ThisWorkbook.Worksheets("ANALYSISDB").Range("A" & Rows.Count).End(xlUp).Row
For Y = 2 To x
If ThisWorkbook.Worksheets("ANALYSISDB").Cells(Y, 1).Value = txt_Search.Text Then
Rows(Y).Delete
End If
Next Y
'Clear Data Entry Form
Me.txt_Search.Value = "-"
Me.txt_Name.Value = "-"
Me.cmb_Phase.Value = "0"
Me.txt_Crest.Value = "0"
Me.txt_GOC.Value = "0"
Me.txt_HWC.Value = "0"
Me.txt_OP.Value = "0"
Me.txt_GasGrad.Value = "0"
Me.txt_OilGrad.Value = "0"
Me.txt_WaterGrad.Value = "0"
Me.txt_RefWell.Value = "-"
Me.chbDisplay.Value = False
Me.chbLabel.Value = False
MsgBox "Data has been deleted", vbInformation
txt_Name.SetFocus
End Sub
Bookmarks