Simpatie.ro - matrimoniale
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
Oanny22 Profile
Femeie
25 ani
Bacau
cauta Barbat
27 - 64 ani
Mrrrr's Forum (VIEW ONLY)InregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[VBA] Macro to Multiply Current Sheet n Times

Pagini: 1 Moderat de TRaP, TonyTzu
pus acum 17 ore#1
TRaP
Moderator
Postari: 979
The first macro is the simple, original macro that multiplies the current sheet with added (1), (2) etc. after current sheet's name, the user having to rename each sheet manually.


Sub CopySheet_PasteMore()
Dim x As Integer
  x = InputBox("Enter number of times to multiply Current Sheet")
  For numtimes = 1 To x
    ActiveWorkbook.ActiveSheet.Copy After:=ActiveWorkbook.ActiveSheet
  Next
End Sub

The second macro is more complex, handles errors and is specifically designed to multiply a sheet named 1 and rename the sheets as 2 to 31. E.g., I have a sheet named 1 for the first day of a month and want it multiplied 30 times - the sheets are renamed automatically 2 - 31. This also copies any dropdown lists I have under Name Manager without alerts and handles errors. It does not have Appliciation.ScreenUpdating = False on purpose. I also have a formula in cell B3 that I'd like updated with the sheet names.

Sub CopySheet_PasteMore()
    Dim x As Long
    Dim i As Long
    Dim ws As Worksheet
    Dim sourceSheet As Worksheet

    On Error GoTo ErrorHandler

    x = Application.InputBox( _
        "Enter number of times to multiply Current Sheet:", _
        Type:=1)

    If x < 1 Then Exit Sub

    Set sourceSheet = ActiveSheet

    Application.DisplayAlerts = False

    For i = 1 To x
        sourceSheet.Copy After:=ActiveWorkbook.ActiveSheet
        Set ws = ActiveSheet
        ws.Name = CStr(i + 1)
        ws.Range("B3").formula = "=data!A" & (i + 1)
    Next i

CleanExit:
    Application.DisplayAlerts = True
    Exit Sub

ErrorHandler:
    MsgBox "A aparut o eroare: " & Err.Description, vbExclamation
    Resume CleanExit

End Sub

Source: ChatGPT


 
   
Pagini: 1  
Mergi la