ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,738
- Office Version
- 2007
- Platform
- Windows
Hi,
I have placed a piece of working code from one worksheet into a new worksheet but now doesnt work work for me.
The worksheet it was taken from was a selection change event "code also works still" where now the worksheet its now in is a change event "doesnt work"
Column B will have a 17 character value entered into the cell.
The 10th character will be shown in RED.
Depending on the 10th character the value then in cell column I will also be RED.
Can you advise what i missed or need to add so no matter what cell etc i am in the code below will make sure and the 10th character in column B will be RED
The selection change code worked only for cell B8 as a new row was added each time.
I changed the range B8 to B8:B50 but still no joy
Code in place is shown below
I have placed a piece of working code from one worksheet into a new worksheet but now doesnt work work for me.
The worksheet it was taken from was a selection change event "code also works still" where now the worksheet its now in is a change event "doesnt work"
Column B will have a 17 character value entered into the cell.
The 10th character will be shown in RED.
Depending on the 10th character the value then in cell column I will also be RED.
Can you advise what i missed or need to add so no matter what cell etc i am in the code below will make sure and the 10th character in column B will be RED
The selection change code worked only for cell B8 as a new row was added each time.
I changed the range B8 to B8:B50 but still no joy
Code in place is shown below
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range
Dim LR As Long
Range("B8").Characters(Start:=10, Length:=1).Font.Color = -16776961
Application.EnableEvents = False
Select Case Mid(Range("B8").Value, 10, 1)
Case Is = "S"
Range("I8").Value = "1995"
Case Is = "T"
Range("I8").Value = "1996"
Case Is = "V"
Range("I8").Value = "1997"
Case Is = "W"
Range("I8").Value = "1998"
Case Is = "X"
Range("I8").Value = "1999"
Case Is = "Y"
Range("I8").Value = "2000"
Case Is = "1"
Range("I8").Value = "2001"
Case Is = "2"
Range("I8").Value = "2002"
Case Is = "3"
Range("I8").Value = "2003"
Case Is = "4"
Range("I8").Value = "2004"
Case Is = "5"
Range("I8").Value = "2005"
Case Is = "6"
Range("I8").Value = "2006"
Case Is = "7"
Range("I8").Value = "2007"
Case Is = "8"
Range("I8").Value = "2008"
Case Is = "9"
Range("I8").Value = "2009"
Case Is = "A"
Range("I8").Value = "2010"
Case Is = "B"
Range("I8").Value = "2011"
Case Is = "C"
Range("I8").Value = "2012"
Case Is = "D"
Range("I8").Value = "2013"
Case Is = "E"
Range("I8").Value = "2014"
Case Is = "F"
Range("I8").Value = "2015"
Case Is = "G"
Range("I8").Value = "2016"
Case Is = "H"
Range("I8").Value = "2017"
Case Is = "J"
Range("I8").Value = "2018"
Case Is = "K"
Range("I8").Value = "2019"
End Select
Application.ScreenUpdating = True
Application.EnableEvents = True
Range("I8").Font.Color = vbRed
LR = Cells(Rows.Count, "A").End(xlUp).Row
On Error GoTo AllowEvents
Application.EnableEvents = False
Application.ScreenUpdating = False
For Each C In Target
If C.Row > 6 And C.Column < 11 And Not IsEmpty(C) Then
If Not C.HasFormula Then
C.Value = UCase(C.Value)
Else
C.Formula = Replace(C.Formula, "=", "=UPPER(") & ")"
End If
End If
Next C
If Target.CountLarge > 1000 Then GoTo AllowEvents
If Not Intersect(Target, Range("B8:B" & LR)) Is Nothing Then
For Each C In Intersect(Target, Range("B8:B" & LR))
If (C.Row > 6) And (C.Row < LR) Then
If Len(C.Value) <> 17 And Len(C.Value) > 0 Then
MsgBox "VIN MUST BE 17 CHARACTERS", vbCritical, "VIN CHARACTER COUNT MESSAGE"
C.Value = ""
C.Select
GoTo AllowEvents
Else
C.Characters(Start:=10, Length:=1).Font.ColorIndex = 3
End If
Else
C.Characters(Start:=10, Length:=1).Font.ColorIndex = 3
End If
Next C
If Range("B8") = "" Then Range("E8") = ""
End If
AllowEvents:
Application.ScreenUpdating = True
Application.EnableEvents = True
Range("B8").Characters(Start:=10, Length:=1).Font.ColorIndex = 3
Range("B8").Font.Size = 18
Range("B8").Font.Bold = True
Range("B8").HorizontalAlignment = xlCenter
Range("B8").VerticalAlignment = xlCenter
Range("B8").Font.Name = "Calibri"
Range("B8").Borders.LineStyle = xlContinuous
Range("B8").Borders.Weight = xlThin
End Sub