Copy sheet and get resulting sheet object?

后端 未结 13 1972
醉梦人生
醉梦人生 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 13:21

    This should be a comment in response to @TimWilliams, but it's my first post so I can't comment.

    This is an example of the problem @RBarryYoung mentioned, related to hidden sheets. There is a problem when you try to put your copy after the last sheet and the last sheet is hidden. It seems that, if the last sheet is hidden, it always retains the highest index, so you need something like

    Dim sht As Worksheet
    
    With ActiveWorkbook
       .Sheets("Sheet1").Copy After:=.Sheets(.Sheets.Count)
       Set sht = .Sheets(.Sheets.Count - 1)
    End With
    

    Similar situation when you try to copy before a hidden first sheet.

    0 讨论(0)
提交回复
热议问题