Results 1 to 6 of 6

Thread: Require macro as soon as possible

  1. #1
    Seeker rakeshbrraag's Avatar
    Join Date
    Nov 2012
    Posts
    10
    Articles
    0
    Excel Version
    2013

    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

    Columns("D:F").Select
    Selection.Copy
    Columns("G:XFD").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Rows("18:18").Select
    Selection.AutoFill Destination:=Rows("18:329"), Type:=xlFillDefault
    Rows("18:329").Select
    Range("C18").Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("C18").Select

    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
    Next


    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
    Hi,

    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

    Regards
    taps

  3. #3
    Seeker rakeshbrraag's Avatar
    Join Date
    Nov 2012
    Posts
    10
    Articles
    0
    Excel Version
    2013
    Hello,

    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
    Hi,

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

    Regards
    taps

  5. #5
    Seeker rakeshbrraag's Avatar
    Join Date
    Nov 2012
    Posts
    10
    Articles
    0
    Excel Version
    2013
    hello,


    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
  •