Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Question

shawleigh17

Board Regular
Joined
Nov 16, 2007
Messages
79
I am trying to write code in a sheet whenever that sheet is changed, but I only want this sheet to be affected, and no others. This sheet is deleted/recreated with each run of the larger program, so I can't really have standing code in the sheet file. Is there a way to do this? I want the sheet to essentially do this: When I change a value in the "From Location" column (B), I want column A to update with the vlookup value.

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If (Sh = Workbooks("WAT_File_Existence_Test.xls").Sheets("Print_Sheet")) Then
        Workbooks.Open ("D:\Personal\O&S_Report.xls")
        Sheets("SKU_Change_Plan").Visible = True
        Sheets("SKU_Change_Plan").Unprotect ("fritoIPM")
        ActiveCell.Offset(0, -1).FormulaR1C1 = "l;l,"
        Dim O_S_Value As Boolean
        O_S_Value = ThisWorkbook.Sheets("Velocity").Range("A9")
        
        If O_S_Value = "True" Then
            Descrp = Application.WorksheetFunction.VLookup(ActiveCell.Value, Workbooks("O&S_Report.xls").Sheets("SKU_Change_Plan").Range("All_Data"), 4, False)
        Else
            Descrp = Application.WorksheetFunction.VLookup(ActiveCell.Value, Workbooks("O&S_Report.xls").Sheets("SKU_Change_Plan").Range("All_Data"), 4, False)
        End If
        
        Application.DisplayAlerts = False
        Workbooks("O&S_Report.xls").Activate
        Sheets("SKU_Change_Plan").Protect ("fritoIPM")
        ActiveWorkbook.SaveAs ("D:\Personal\O&S_Report.xls")
        ActiveWorkbook.Close
        Application.DisplayAlerts = True
    
    End If

End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,048
Messages
6,122,862
Members
449,097
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