0

I have this block of code:

Sub Clean_Data()

    Columns("K:K").Select
    Selection.Delete Shift:=xlToLeft
    Range("J2").Select
    ActiveCell.FormulaR1C1 = "BAU"
    Range("J3").Select
    ActiveWindow.ScrollColumn = 12
    ActiveWindow.ScrollColumn = 26
    ActiveWindow.ScrollColumn = 33
    Columns("AO:BE").Select
    Selection.Delete Shift:=xlToLeft
    Range("AO13").Select
    ActiveWindow.ScrollColumn = 1
End Sub

I would like it to run on a specific sheet only. I tried doing it using With but nothing seems to work. Can you anyone help out?

Thanks!

braX
  • 11,506
  • 5
  • 20
  • 33
Antoine
  • 31
  • 2
  • 1
    See: https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba – Scott Craner Apr 27 '22 at 20:09
  • Hi, thank you for your response. I'm new to VBA and just trying to make a file we have easy to understand. I tried out a few of these solutions but can't seem to have it work. Any help would be greatly appreciated – Antoine Apr 28 '22 at 13:47
  • If you use "select" or "activate" of a cell, then the macro should run on the active sheet. Avoid using "select" or "activate". Say, your specific sheet's name is "bla". Then you use `with sheets("bla")` ---> `.column("K:K").Delete Shift:=xlToLeft` ---> `.Range("J3").FormulaR1C1 = "BAU"` --->`.Columns("AO:BE").Delete Shift:=xlToLeft` ---> `end with` ---> `end sub` – karma Apr 29 '22 at 14:14

0 Answers0