Hello all! First off I'd like to thank anyone for any help given. Here goes:
I've got a workbook that has six worksheet templates within it. Each one has a different number of hidden columns. It is used for serial number input from a barcode scanner. The idea is that when you scan a bar code, it automatically duplicate checks against the rest of the entire workbook, but if that isn't possible at least against the rest of the worksheet. The first one that I tried, on the 2 column worksheet worked! This is what the code looked like:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
Target.Offset(0, 1).Select
ElseIf Target.Column = 3 Then
Target.Offset(1, -1).Select
With Application
.ScreenUpdating = False
.EnableEvents = True
End With
If Not Application.Intersect(Range("C3:C2002"), Target) Is Nothing Then
ActiveSheet.Unprotect
Rows(Target.Row + 1).Hidden = Target.Value <= 0
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If
End Sub
Private Sub Worksheet_Change2(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("B3:xlCellTypeVisible")) Is Nothing Then Duplicate_Check2
End Sub
With Duplicate_Check2 being:
Sub Duplicate_Check2()
ActiveSheet.Unprotect
ActiveSheet.Range("B3:C2002").Rows.SpecialCells(xlCellTypeVisible).Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
However when I updated this and tried it for the three column template, it doesn't work. Here is the code for that:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
Target.Offset(0, 1).Select
ElseIf Target.Column = 3 Then
Target.Offset(0, 1).Select
ElseIf Target.Column = 4 Then
Target.Offset(1, -2).Select
With Application
.ScreenUpdating = False
.EnableEvents = True
End With
If Not Application.Intersect(Range("D3:D2002"), Target) Is Nothing Then
ActiveSheet.Unprotect
Rows(Target.Row + 1).Hidden = Target.Value <= 0
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If
End Sub
Private Sub Worksheet_Change2(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("B3:xlCellTypeVisible")) Is Nothing Then Duplicate_Check3
End Sub
And Duplicate_Check3 being:
Sub Duplicate_Check3()
ActiveSheet.Unprotect
ActiveSheet.Range("B3:D2002").Rows.SpecialCells(xlCellTypeVisible).Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
What the heck am I doing wrong? It works perfectly for the two column sheet and not at all for the three column sheet. Any suggestions?
Thank you for your time,
-Robb-
Bookmarks