emirmansouri
New Member
- Joined
- May 31, 2012
- Messages
- 42
I have the below code but it only returns the values once I go into each cell and press enter, what I would like to achieve is to have all the row values returned instead of only the one row.
Any help will be greatly appreciated.
Any help will be greatly appreciated.
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Row As Long
Dim ws As Worksheet
Dim Cel As Range
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Set Target = Target(1, 1)
Row = Target.Row
If Row > 1 Then
If Target.Column = 2 Then
If Target.Value = "" Then
Target.EntireRow.Delete
Else
For Each ws In Worksheets
If ws.CodeName Like "WSTemplate*" Then
With ws
Set Cel = .Range("B:B").Find(What:=Range("B" & Row).Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Not Cel Is Nothing Then
Cel.EntireRow.Copy Destination:=Range("A" & Row)
Do While .Range("A" & Cel.Row).MergeArea.Cells.Count = 1
Set Cel = Cel.Offset(-1, 0)
Loop
Range("O" & Row).Value = .Name
Range("P" & Row).Value = .Range("A" & Cel.Row).Value
GoTo Finalize:
End If
End With
End If
Next
End If
Else
For Each ws In Worksheets
If ws.CodeName Like "WSTemplate*" Then
With ws
Set Cel = .Range("B:B").Find(What:=Range("B" & Row).Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Not Cel Is Nothing Then
Range("A" & Row & ":N" & Row).Copy Destination:=.Range("A" & Cel.Row)
GoTo Finalize:
End If
End With
End If
Next
End If
End If
Finalize:
Call AddBorders(Range("B" & Row & ":P" & Row), xlThin, True, True)
Target.Select
ExitSub:
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
Set Cel = Nothing
Set ws = Nothing
End Sub