Consulting

Results 1 to 3 of 3

Thread: Insert sheet

  1. #1

    Insert sheet

    is there a way to insert a sheet as sheet4 not matter what?

    I have code that runs and a new sheet gets inserted. The first time through it is sheet4, this is fine. But if the user chooses to run the code again, the sheet now becomes sheet5. The code references sheet4, so obviously it will error out because sheet4 does not exist in the workbook.

    Is there any way around this?

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What happens if there is already Sheet4?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    presumably the code has the likes of
    [vba]Sheets.add[/vba] in it, and you refer to it with the likes of
    [vba]Sheets("Sheet4").range("A1")[/vba]
    Replace with
    [vba]Set xxx = Sheets.Add[/vba] and refer to it as
    [vba]xxx.range("A1")[/vba] etc.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •