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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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