alternate method please

rakeshbrraag

New member
Joined
Nov 23, 2012
Messages
10
Reaction score
0
Points
0
Excel Version(s)
2013
Hello everyone,

I have a code which copies specific columns certain number of times, Here is the code:

Code:
Sub Copy_Columns()
Dim lastr As Double
Dim cols As Double
    cols = Sheets("Sheet1").Range("V4").Value * 3       ' Determine how many columns to copy across
[COLOR=#ff0000]    With Sheets("Sheet2")[/COLOR]
        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
    End With
End Sub


Can anyone help me with the second line(marked in red). I want the same code working without With as i am getting some errors when looping this code
 
Last edited by a moderator:
What error are you getting, and where are you trying to copy to, which sheet.
 
Hello Bob,

Thank you for your reply. To be clear i have two codes:


code 1: This code duplicates the sheet name" template" specific number of times and renames it automatically.

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

Code2: This code copies the the columns DEF to (GHI, JKL,MNO,PQR,STU,VWX.......etc to specific number of times) in the sheet named Campaingn_1

Sub test_test()
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

End With
End Sub






What i need is the second code should run in all the sheets created by the first code( i.e the duplications of the sheets templete). Please do help me.
 
I don't see that answers my questions, and you keep starting new threads. Keep one question in one thread!
 
Back
Top