Help modifying code of VBA Worksheet Change Event

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.


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
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top