ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,738
- Office Version
- 2007
- Platform
- Windows
Morning,
I seem to be doing this more often lately but dont get the correct idea of doing it.
Can you advise a rule of thumb please.
I have this existing code.
And i need to add this also into it.
I seem to be doing this more often lately but dont get the correct idea of doing it.
Can you advise a rule of thumb please.
I have this existing code.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)Dim r As Range
On Error GoTo errHandle 'if we encounter an error, handle it
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Address = "$A$6" Then
With Sheets("INFO").Range("CG2")
If Len(.Offset(1).Value) Then
Set r = .End(xlDown).Offset(1)
With .End(xlDown).Offset(1)
.Value = UCase$(ActiveSheet.Cells(6, 1).Value)
.Interior.ColorIndex = 6
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.VerticalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.RowHeight = 19.5
.Font.Bold = True
With ActiveWorkbook.Worksheets("INFO").Sort
.SetRange Range("CG2:CG500")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End If
End With
End If
With Target
If .Column <> 13 And .Count = 1 And Not .HasFormula Then
.Value = UCase$(.Value)
End If
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
errHandle:
'If an error occurs, code below will execute ensuring events and updating are re-enabled
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox Err.Description, vbCritical, "Error number: " & Err.Number
End Sub
And i need to add this also into it.
Code:
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("J9")) Is Nothing Then
If Target.Value <> "" And Target.Cells.Count = 1 Then
Application.EnableEvents = False
On Error Resume Next
Columns("D:D").Find(Target.Value, , , xlWhole, , xlNext).Select
On Error GoTo 0
Application.EnableEvents = True
End If
End If
End Sub