Consulting

Results 1 to 4 of 4

Thread: Solved: Copy worksheets with msg box

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Location
    Texas
    Posts
    62
    Location

    Solved: Copy worksheets with msg box

    I need assistance with the following Macro......... I want to create multiple copies of a sheet called "data" based on variable criteria....place them after the data sheet.... If they could be renamed data1, data2, etc. that would be an added bonus...... What I have now simply creates blank sheets............. Thanks in advance.....

    [VBA]
    Sub AddHowMany()
    ' Turns the screen off while the Macro is running.
    Application.ScreenUpdating = False
    'Prompt user for total number of new sheets needed, then repeats based on answer
    totalsheets = InputBox("How many copies of the worksheet do you want to create?")
    For X = 1 To totalsheets
    Worksheets.Add After:=Worksheets(Worksheets.Count), Count:=X
    Next X
    'Turns the screen back on when the Macro is finished.
    Application.ScreenUpdating = True
    End Sub
    [/VBA]

    EDIT: Added VBA tags Tommy

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi Pam in TX

    Try This

    [VBA]
    Sub AddHowMany()
    Dim mNewSht As Worksheet
    ' Turns the screen off while the Macro is running.
    Application.ScreenUpdating = False
    'Prompt user for total number of new sheets needed, then repeats based on answer
    totalsheets = InputBox("How many copies of the worksheet do you want to create?")
    ActiveSheet.Cells.Select
    Selection.Copy
    For x = 1 To totalsheets
    Set mNewSht = Worksheets.Add(After:=Worksheets(Worksheets.Count))
    mNewSht.Name = "data" & CStr(x)
    mNewSht.Paste
    Next x
    'Turns the screen back on when the Macro is finished.
    Application.ScreenUpdating = True
    End Sub
    [/VBA]

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Location
    Texas
    Posts
    62
    Location
    Perfect...... Thanks neighbor..........

    I am still very new to this...... and still run into many problems.... Maybe one day I can be smart also....

    Thanks again..........

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Too many longhorns in this thread for this okie to be comfortable...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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