Macro that works on one workbook but not another

dvuppx

New Member
Joined
Aug 31, 2017
Messages
12
i have two almost identical workbooks to record service activity in two different teams. i have a macro running on worksheet A but the same macro doesnt work on worksheet B.

here is the code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)
'' dvuppx
'
Dim Ws As Worksheet

Application.EnableEvents = False


On Error GoTo Xit
If Target.Column <> 70 Or UCase(Target.Value) <> "YES" Then GoTo Xit


Set Ws = Sheets("121 Disch")
Target.EntireRow.Copy Ws.Range("A" & Rows.Count).End(xlUp).Offset(1)
Ws.Range("BP" & Rows.Count).End(xlUp).Offset(, 1) = Date
Target.EntireRow.Delete
Xit:
Application.EnableEvents = True


End Sub


the aim is to input the word 'yes' in column BN on the sheet named '121 C+D' and for the row to then move to the sheet '121 Disch' and add the date on the end of the show. I have no idea why this works perfectly on one but the other. any help would be appreciated.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Re: Help with a macro that works on one workbook but not another

Does the code exist in both worksheets? You could remove the On Error line too, i.e.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim Ws As Worksheet
    
    With Target
        If .column <> 70 Or UCase(.Value) <> "YES" Then Exit Sub
        
        Application.EnableEvents = False
        Set Ws = Sheets("121 Disch")
        .EntireRow.Copy Ws.Range("A" & Rows.Count).End(xlUp).Offset(1)
        Ws.Range("BP" & Rows.Count).End(xlUp).Offset(, 1) = Date
        .EntireRow.Delete
        Application.EnableEvents = True
        Set Ws = Nothing
    End With
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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