Run Time Error '1004': Select method of Range Class failed VBA 2003

后端 未结 3 1894
抹茶落季
抹茶落季 2021-01-22 19:55

I am trying to copy a column from one sheet to another. The code I am using is a recorded macro and it works fine until I connect it to a button. When I do so, it gives a

3条回答
  •  感动是毒
    2021-01-22 20:35

    I think the issue is that you have written the code in another sheet's code module. If I'm in Sheet1, and write e.g.

    Sheets("Sheet2").Select
    Columns("A:A").Select
    

    ...then Excel assumes you are referring to the Columns on Sheet1 as it treats the current sheet as a default. Therefore, you've told Excel "select Sheet 2" then "select a column on Sheet 1"...which it can't do so it gives you an error message. The best solution would be not to use 'Select'...but you will still see in Siddharth's code that he has had to refer to sheet addresses explicitly

    Your original code would have worked if placed in the ThisWorkbook module. Locations for entering code are explained towards the end of this Excel help video

提交回复
热议问题