0

I have a large file and in that I have one function which changes the color if the cell value is changed.

Now it works properly with Worksheet_Change when I put it in the sheet 1 in VBA!

But I want to do some copy pasting in the sheet before I download the new file.

How can I assign a macro to activate this code on VBA sheet so it only works in the new the file downloaded? Or is there a button I can add so it calls it after?

Thank you!

Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("$A:$AQ")) Is Nothing Then
     Range(Target.Address).Select
   
     With Selection.Interior
       .Pattern = xlSolid
       .PatternColorIndex = xlAutomatic
       .ThemeColor = xlThemeColorAccent6
      .TintAndShade = 0
       .PatternTintAndShade = 0
    End With
   End If
End Sub

I want this to work in SHeet1 of the downloaded file not the Sheet one from the Master File.

  • 1
    I think maybe you want to use an add-in? It's just an Excel file in XLAM format, and you load it into your system to run code on workbooks that don't have code. – braX Jun 09 '23 at 11:32
  • 1
    If it is just the `Worksheet_Change` event that you want to add in that new Excel file (*which should be available only for that file*), then that is possible as shown in [Excel vba add code to sheet module programmatically](https://stackoverflow.com/questions/34837006/excel-vba-add-code-to-sheet-module-programmatically) – Siddharth Rout Jun 09 '23 at 11:38
  • What does "the subsequent file" mean? Do you want copying a specific sheet existing event code, to a downloaded file? If so, is that file of Macro-enabled type (xlsm, xlsb etc.)? If not and you need to keep the copied event, may the file be saved as .xlsm? Or, does the macro event in discussion in the downloaded file and you want copying it in another workbook? – FaneDuru Jun 09 '23 at 11:56
  • Subsequent file is the new file, Yes I want to cpy the existing event code only on the downloaded file, not the Master one. The downloaded file is Macroenabled – Himanshu TOMAR Jun 09 '23 at 12:00
  • If you want to be able to bypass the Worksheet_Change *only* in the Master copy, you could add some code to check the path of the workbook and exit the change sub if it's located in a specific location. – Tim Williams Jun 09 '23 at 16:28

0 Answers0