I have two worksheets and in Sheet2 I have code in worksheet change event
Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x, ws As Worksheet, c As Range, shp As Shape, iCol As Long
If Target.Cells.CountLarge > 1 Then Exit Sub
If Target.Address = "$A$2" Then
Application.ScreenUpdating = False
Set ws = Sheet1
With Columns("B:Z")
.Interior.Color = xlNone
.Borders.Value = 0
.ClearContents
.ClearComments
End With
x = Application.Match(Target.Value, ws.Columns(2), 0)
If Not IsError(x) Then
ws.Range("B4:B8").Copy Range("B3")
For Each shp In Me.Shapes
If shp.Type = msoFormControl Then shp.Delete
Next shp
iCol = 3
For Each c In ws.Range("E6:KQ6").Cells
If c.Value <> Empty Then
ws.Range(ws.Cells(4, c.Column), ws.Cells(8, c.Column)).Copy Cells(3, iCol)
ws.Cells(x, c.Column).Copy Cells(8, iCol)
iCol = iCol + 1
End If
Next c
ws.Cells(x, "B").Copy Range("B8")
Range("B8").Value = Empty
End If
Application.ScreenUpdating = True
End If
End Sub
Any idea why this fault happens?