TheGrandPooba
New Member
- Joined
- Jul 1, 2022
- Messages
- 12
- Office Version
- 365
- Platform
- Windows
Hi all,
I keep getting "Compile Error: Member already exists in an object module from which this object module derives" when trying to run this code:
The error highlights 'Sub Protection(proWS As Worksheet, PAction As Boolean)'
The main chunk of the code is from my last post, VBA to lookup order#, Lookup Order#, Copy Paste data into history, then delete orders
The generous code from mumps hadn't accounted for unprotecting/re-protecting the OrderImport and OrderHistory tabs.
Can anyone help figure out how to unprotect the OrderImport/OrderHistory tabs, then reprotect them after the With loop runs?
Thanks all, I appreciate you
I keep getting "Compile Error: Member already exists in an object module from which this object module derives" when trying to run this code:
VBA Code:
Const strPassword As String = "Soybean?"
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) <> "G3" Then Exit Sub
Dim srcWS As Worksheet, desWS As Worksheet, rng As Range
Set srcWS = Worksheets("OrderImport")
Set desWS = Worksheets("OrderHistory")
Call Protection(srcWS, False)
Call Protection(desWS, False)
Application.ScreenUpdating = False
With srcWS.ListObjects("OImport")
.Range.AutoFilter 1, Target.Value
.DataBodyRange.SpecialCells(xlCellTypeVisible).Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1)
Set rng = .DataBodyRange.SpecialCells(xlCellTypeVisible).Cells
.DataBodyRange.AutoFilter Field:=1
rng.Delete
End With
Call Protection(srcWS, True)
Call Protection(desWS, True)
Application.ScreenUpdating = True
End Sub
Sub Protection(proWS As Worksheet, PAction As Boolean)
If PAction = True Then
proWS.Protect Password:=strPassword
Else
proWS.Unprotect Password:=strPassword
End If
End Sub
The main chunk of the code is from my last post, VBA to lookup order#, Lookup Order#, Copy Paste data into history, then delete orders
The generous code from mumps hadn't accounted for unprotecting/re-protecting the OrderImport and OrderHistory tabs.
Can anyone help figure out how to unprotect the OrderImport/OrderHistory tabs, then reprotect them after the With loop runs?
Thanks all, I appreciate you