Private Sub Worksheet_Change(ByVal Target As Range) - Copy and paste issue?

30136353

Board Regular
Joined
Aug 14, 2019
Messages
105
I have the following code which changes a cells interior when changed, and inputs a "1" in column W. Doesn't seem to work with copy and paste? The interior colour change works, but the input of "1" will only work with a single entry... any help?

VBA Code:
     Private Sub Worksheet_Change(ByVal Target As Range)

     Dim rngtemp1 As Range
     Dim rngTemp3 As Range
     Dim wsTemp As Worksheet
     Dim lngLastRow As Long, RR As Long

    If ThisWorkbook.ActiveSheet.Name = "TRIAL" Then

    Set wsTemp = ThisWorkbook.Worksheets("TRIAL")
    lngLastRow = wsTemp.Range("D" & Rows.Count).End(xlUp).Row
    Set rngtemp1 = wsTemp.Range("J2:U" & Trim(Str(lngLastRow)))
    
    If Not Intersect(Target, rngtemp1) Is Nothing Then
        With Target.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
            .PatternTintAndShade = 0
      
    End With
    Set rngTemp3 = wsTemp.Range("W" & (Target.Row))
    rngTemp3.Value = "1"
    End If
    End If

    End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try
VBA Code:
    Set rngTemp3 = Intersect(Target.EntireRow, wsTemp.Range("W:W"))
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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