I'm very new to VBA, but so far I've been able to work myself through everything I'd need. However, I can't seem to sort-out this issue. I technically have 2 different private subs (Worksheet_Change), but I could only get them to work if I combined them. The first one limits the number of cells with identical content in column B to 3.
The second clears range G:I, and copies range A:F if the value of H = 100. "Macro1" gives me this run-time error (Run-time Error '13': Type Mismatch) when I clear contents for some reason. Obviously, "Macro2" is clearing contents, so I'm really working against myself.
Private Sub Worksheet_Change(ByVal Target As Range)
'First Macro. (The issue is in this Macro)
If WorksheetFunction.CountIf(Range("B4:B350"), Target) > 3 Then
msgbox "This team member has the maximum number of open projects.", vbCritical, "Overburdened"
Target.Value = ""
Target.Select
End If
'Second Macro
Dim rngStart As Range
Set rngStart = ActiveCell
A = Worksheets("Project Tracking").Cells(Rows.Count, 1).End(xlUp).Row
For i = 4 To A
If Worksheets("Project Tracking").Cells(i, 8).Value = 100 Then
Worksheets("Project Tracking").Range(Cells(i, 7), Cells(i, 9)).ClearContents
Worksheets("Project Tracking").Range(Cells(i, 1), Cells(i, 6)).Copy
Worksheets("Completed Projects").Activate
B = Worksheets("Completed Projects").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Completed Projects").Cells(B + 1, 1).Select
ActiveSheet.Paste
Worksheets("Project Tracking").Activate
Worksheets("Project Tracking").Range(Cells(i, 1), Cells(i, 6)).ClearContents
Call Reset_List
Call Macro3
End If
Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Project Tracking").Cells(1, 1).Select
rngStart.Select
End Sub
Range()
with the Worksheet "Project Tracking"? When you do that withRange()
, you need to do that with theCells()
reference in there as well. So just doWorksheets("Project Tracking").Range(Worksheets("Project Tracking").Cells(i, 1), Worksheets("Project Tracking").Cells(i, 6)).ClearContents
– BruceWayne_Change()
event is causing changes (i.e. calling itself), you should be able to prevent it by placingApplication.EnableEvents = False
at the beginning of the Sub andApplication.EnableEvents = True
at the end. – Mistella