Copy sheet and get resulting sheet object?

后端 未结 13 2164
醉梦人生
醉梦人生 2020-11-28 12:21

Is there any easy/short way to get the worksheet object of the new sheet you get when you copy a worksheet?

ActiveWorkbook.Sheets(\         


        
13条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 12:54

    It is correct that hidden worksheets cause the new worksheet index to be non-sequential on either side of the source worksheet. I found that Rachel's answer works if you're copying before. But you'd have to adjust it if you're copying after.

    Once the model is visible and copied, the new worksheet object is simply the ActiveSheet whether you copy the source before or after.

    As a preference, you could replace:

    Set newSheet = .Previous with Set newSheet = Application.ActiveSheet.

    Hope this is helpful to some of you.

提交回复
热议问题