Results 1 to 6 of 6

Thread: Require macro as soon as possible

  1. #1

    Lightbulb Require macro as soon as possible

    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello Everyone,

    I have a problem with joining the two macros.

    This is the first macro: This macro copies certain columns and rows multiple times in the sheet.

    Dim lastr As Double
    Dim cols As Double

    cols = Sheets("row").Range("V4").Value * 3 ' Determine how many columns to copy across
    With Sheets("campaingn_1")
    lastr = .UsedRange.Rows.Count ' Last used row in worksheet
    .Range("D1:F" & lastr).Select
    Selection.AutoFill Destination:=Range(Cells(1, 4), Cells(lastr, cols + 3)), Type:=xlFillDefault

    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.AutoFill Destination:=Rows("18:329"), Type:=xlFillDefault
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False

    End With

    Here is the second Macro: This macro duplcates the sheet( " template") and also renames those duplicated sheets specific number of times.

    Dim iLoop As Integer, iCount As Integer

    iCount = Sheets("Row").Range("V1").Value

    For iLoop = 1 To iCount
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = "Campaign_" & iLoop
    ActiveSheet.Range("C2").Value = Sheets("Row").Range("T" & iLoop + 3).Value

    Now i need a single macro which works like this:

    It has to execute the second macro( duplication of the sheet "row" specific number of times) and execute the first macro in each and every duplicated sheets( here the duplication of sheets is done by second macro as explained above). please help me out with this as soon as possible

    Thanks in advance

  2. #2

    Put the first macro inside a procedure like below.

    Sub First_Macro()

    ' Put your entire codes here

    End Sub

    Now, Call this macro inside the For loop of 2nd Macro. (Just type below codes).

    Call First_Macro


  3. #3

    Thank you for your response. I am facing a small problem with this code as i am getting error in first macro, 2nd line in the code: With Sheets("campaingn_1") . This is because this specifies do some actions in Sheet name " Campaingn_1". But the second macro duplicates a specific sheet 4 times and renames it as campaingn_1, campaingn_2, campaingn_3,campaingn_4. Can you please help me out with this looping problem . Thanks in advance

  4. #4

    Replace With Sheets("campaingn_1") by With ActiveSheet and Let me know the status.


  5. #5

    Great, its working . Thank you very much for your knowledge transfer.

  6. #6
    You are most welcome

Posting Permissions

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