I keep getting error message "member already exists in an object module from which this project module derives

TonyAFG

New Member
Joined
Aug 9, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Option Explicit

Function Validate() As Boolean

    Dim frm As Worksheet
    
    Set frm = ThisWorkbook.Sheets("Form")

    Validate = True
    
    With frm
    
        .Range("I6").Interior.Color = xlNone
        .Range("I8").Interior.Color = xlNone
        .Range("I10").Interior.Color = xlNone
        .Range("I12").Interior.Color = xlNone
    
    End With
    
    'Fish Type
    
    If Trim(frm.Range("I6").Value) <> "Whiting" And Trim(frm.Range("I6").Value) <> "Bottom Fish" And Trim(frm.Range("I6").Value) <> "Crab" Then
        MsgBox "Please Select Fish Type.", vbOKOnly + vbInformation, "Fish Type"
        frm.Range("I6").Select
        frm.Range("I6").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If
    
    'Finished Pounds
    
    If Trim(frm.Range("I8").Value) <> "" Or Not IsNumeric(Trim(frm.Range("I8").Value)) Then
        MsgBox "Finished Pounds is blank.", vbOKOnly + vbInformation, "Finished Pounds"
        frm.Range("I8").Select
        frm.Range("I8").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If
        
     'Sales Per Pound
    
    If Trim(frm.Range("I10").Value) <> "" Or Not IsNumeric(Trim(frm.Range("I10").Value)) Then
        MsgBox "Sales Per Pound is Blank.", vbOKOnly + vbInformation, "Sales Per Pound"
        frm.Range("I10").Select
        frm.Range("I10").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If
    
      'Cost Per Pound
    
    If Trim(frm.Range("I12").Value) <> "" Or Not IsNumeric(Trim(frm.Range("I12").Value)) Then
        MsgBox "Cost Per Pound is Blank.", vbOKOnly + vbInformation, "Cost Per Pound"
        frm.Range("I12").Select
        frm.Range("I12").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If


End Function



Sub Reset()

    With Sheets("form")
    
        .Range("I6").Interior.Color = xlNone
        .Range("I6").Value = ""
        
        .Range("I8").Interior.Color = xlNone
        .Range("I8").Value = ""
        
        .Range("I10").Interior.Color = xlNone
        .Range("I10").Value = ""
        
        .Range("I12").Interior.Color = xlNone
        .Range("I12").Value = ""
        
    End With

End Sub

Sub Save()

      Dim frm As Worksheet
      Dim data As Worksheet
      
      Dim iRow As Long
      Dim iSerial As Long
      
      Set frm = ThisWorkbook.Sheets("Form")
      
      Set data = ThisWorkbook.Sheets("Data")
      
      If Trim(frm.Range("M1").Value) = "" Then
        
        iRow = data.Range("A" & Application.Rows.Count).End(xlUp).Row + 1
        
        iSerial = data.Cells(iRow - 1, 1).Value + 1
        
        Else
        
            iRow = frm.Range("L1").Value
            iSerial = frm.Range("M1").Value
            
        End If
    
        With data
        
        .Cells(iRow, 1).Value = iSerial
        
        .Cells(iRow, 2).Value = frm.Range("I6").Value
        
        .Cells(iRow, 3).Value = frm.Range("I8").Value
        
        .Cells(iRow, 4).Value = frm.Range("I10").Value
        
        .Cells(iRow, 5).Value = frm.Range("I12").Value
        
        
        .Cells(iRow, 6).Value = Application.UserName
        .Cells(iRow, 7).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
        
        
    End With
    
    
    frm.Range("L1").Value = ""
    frm.Range("M1").Value = ""
    
    
End Sub

Sub Modify()

    Dim iRow As Long
    Dim iSerial As Long
    
    
    iSerial = Application.inoutbox("please enter Fish type to make Modification.", "modify", , , , , 1)
    
    On Error Resume Next
    
    iRow = Application.WorksheetFunction(Application.WorksheetFunction.Match(iSerial, Sheets("data").Range("A:A"), 0))
    
    On Error GoTo 0
    
    If iRow = 0 Then
    
        MsgBox "No record is found.", vbOKOnly + vbCritical, "No record"
        Exit Sub
        
    End If
    
    
    Sheets("Form").Range("L1").Value = iRow
    Sheets("Form").Range("M1").Value = iSerial
    
    
    Sheets("form").Range("I6").Value = Sheets("data").Cells(iRow, 2).Value
    
    Sheets("form").Range("I8").Value = Sheets("data").Cells(iRow, 3).Value

    Sheets("form").Range("I10").Value = Sheets("data").Cells(iRow, 4).Value
    
    Sheets("form").Range("I12").Value = Sheets("data").Cells(iRow, 5).Value
    

End Sub

Sub Delete()

    Dim iRow As Long
    Dim iSerial As Long
    

    iSerial = Application.InputBox("Please Enter Fish Type to delete record.", "Delete", , , , , , 1)
    
    On Error Resume Next
    
     iRow = Application.WorksheetFunction(Application.WorksheetFunction.Match(iSerial, Sheets("data").Range("A:A"), 0))
    
    On Error GoTo 0
    
    If iRow = 0 Then
    
        MsgBox "No record found.", vbOKOnly + vbCriticial, "No Record"
        Exit Sub
    
    End If
    
    Sheets("data").Cells(iRow, 1).EntireRow.Delete shift:=xlUp
    
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
VBA Code:
Option Explicit

Function Validate() As Boolean

    Dim frm As Worksheet
   
    Set frm = ThisWorkbook.Sheets("Form")

    Validate = True
   
    With frm
   
        .Range("I6").Interior.Color = xlNone
        .Range("I8").Interior.Color = xlNone
        .Range("I10").Interior.Color = xlNone
        .Range("I12").Interior.Color = xlNone
   
    End With
   
    'Fish Type
   
    If Trim(frm.Range("I6").Value) <> "Whiting" And Trim(frm.Range("I6").Value) <> "Bottom Fish" And Trim(frm.Range("I6").Value) <> "Crab" Then
        MsgBox "Please Select Fish Type.", vbOKOnly + vbInformation, "Fish Type"
        frm.Range("I6").Select
        frm.Range("I6").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If
   
    'Finished Pounds
   
    If Trim(frm.Range("I8").Value) <> "" Or Not IsNumeric(Trim(frm.Range("I8").Value)) Then
        MsgBox "Finished Pounds is blank.", vbOKOnly + vbInformation, "Finished Pounds"
        frm.Range("I8").Select
        frm.Range("I8").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If
       
     'Sales Per Pound
   
    If Trim(frm.Range("I10").Value) <> "" Or Not IsNumeric(Trim(frm.Range("I10").Value)) Then
        MsgBox "Sales Per Pound is Blank.", vbOKOnly + vbInformation, "Sales Per Pound"
        frm.Range("I10").Select
        frm.Range("I10").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If
   
      'Cost Per Pound
   
    If Trim(frm.Range("I12").Value) <> "" Or Not IsNumeric(Trim(frm.Range("I12").Value)) Then
        MsgBox "Cost Per Pound is Blank.", vbOKOnly + vbInformation, "Cost Per Pound"
        frm.Range("I12").Select
        frm.Range("I12").Interior.Color = vbRed
        Validate = False
        Exit Function
    End If


End Function



Sub Reset()

    With Sheets("form")
   
        .Range("I6").Interior.Color = xlNone
        .Range("I6").Value = ""
       
        .Range("I8").Interior.Color = xlNone
        .Range("I8").Value = ""
       
        .Range("I10").Interior.Color = xlNone
        .Range("I10").Value = ""
       
        .Range("I12").Interior.Color = xlNone
        .Range("I12").Value = ""
       
    End With

End Sub

Sub Save()

      Dim frm As Worksheet
      Dim data As Worksheet
     
      Dim iRow As Long
      Dim iSerial As Long
     
      Set frm = ThisWorkbook.Sheets("Form")
     
      Set data = ThisWorkbook.Sheets("Data")
     
      If Trim(frm.Range("M1").Value) = "" Then
       
        iRow = data.Range("A" & Application.Rows.Count).End(xlUp).Row + 1
       
        iSerial = data.Cells(iRow - 1, 1).Value + 1
       
        Else
       
            iRow = frm.Range("L1").Value
            iSerial = frm.Range("M1").Value
           
        End If
   
        With data
       
        .Cells(iRow, 1).Value = iSerial
       
        .Cells(iRow, 2).Value = frm.Range("I6").Value
       
        .Cells(iRow, 3).Value = frm.Range("I8").Value
       
        .Cells(iRow, 4).Value = frm.Range("I10").Value
       
        .Cells(iRow, 5).Value = frm.Range("I12").Value
       
       
        .Cells(iRow, 6).Value = Application.UserName
        .Cells(iRow, 7).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
       
       
    End With
   
   
    frm.Range("L1").Value = ""
    frm.Range("M1").Value = ""
   
   
End Sub

Sub Modify()

    Dim iRow As Long
    Dim iSerial As Long
   
   
    iSerial = Application.inoutbox("please enter Fish type to make Modification.", "modify", , , , , 1)
   
    On Error Resume Next
   
    iRow = Application.WorksheetFunction(Application.WorksheetFunction.Match(iSerial, Sheets("data").Range("A:A"), 0))
   
    On Error GoTo 0
   
    If iRow = 0 Then
   
        MsgBox "No record is found.", vbOKOnly + vbCritical, "No record"
        Exit Sub
       
    End If
   
   
    Sheets("Form").Range("L1").Value = iRow
    Sheets("Form").Range("M1").Value = iSerial
   
   
    Sheets("form").Range("I6").Value = Sheets("data").Cells(iRow, 2).Value
   
    Sheets("form").Range("I8").Value = Sheets("data").Cells(iRow, 3).Value

    Sheets("form").Range("I10").Value = Sheets("data").Cells(iRow, 4).Value
   
    Sheets("form").Range("I12").Value = Sheets("data").Cells(iRow, 5).Value
   

End Sub

Sub Delete()

    Dim iRow As Long
    Dim iSerial As Long
   

    iSerial = Application.InputBox("Please Enter Fish Type to delete record.", "Delete", , , , , , 1)
   
    On Error Resume Next
   
     iRow = Application.WorksheetFunction(Application.WorksheetFunction.Match(iSerial, Sheets("data").Range("A:A"), 0))
   
    On Error GoTo 0
   
    If iRow = 0 Then
   
        MsgBox "No record found.", vbOKOnly + vbCriticial, "No Record"
        Exit Sub
   
    End If
   
    Sheets("data").Cells(iRow, 1).EntireRow.Delete shift:=xlUp
   
End Sub
It's specifically the Sub Delete ()
 
Upvote 0
Which line in Sub Delete() does the code error on?
 
Upvote 0
Possibly because delete is a used VBA constant. Could you change it to something like Sub myDelete() to see if will work?
 
Upvote 0
Solution

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top