+ Reply to Thread
Results 1 to 5 of 5

Copy and Special Paste Loop

Hybrid View

TexasBobcat Copy and Special Paste Loop 08-14-2015, 10:31 AM
stnkynts Re: Copy and Special Paste... 08-14-2015, 10:39 AM
TexasBobcat Re: Copy and Special Paste... 08-14-2015, 10:54 AM
stnkynts Re: Copy and Special Paste... 08-14-2015, 05:08 PM
LJMetzger Re: Copy and Special Paste... 08-17-2015, 01:14 PM
  1. #1
    Registered User
    Join Date
    08-13-2015
    Location
    Houston, Texas
    MS-Off Ver
    2010
    Posts
    61

    Unhappy Copy and Special Paste Loop

    Happy Friday!

    I am in need of assistance with a problem I am having.
    I am trying to come up with a code that will allow be to copy a set of rows and paste them in a column on a continuous loop.

    Currently I have the code :
    Sub TerminalReserve()
    Dim TermReserve As Range
    Dim Cell As Range
    Dim DurationAddress As String
    Dim PlanName As String
    Dim IssueAge As String
    Dim Duration As String
    Dim Factor As String
    Dim x As Integer
    Dim PlanNameAddress As String
    Dim rowdum As Variant
    Dim counter As Integer
    Dim ReserveName As String
    Dim IssueNameAddress As String
    Dim IssuingAge As String
    Dim FactorAddress As String
    Dim y As Integer
    
    
    'HardCoding of PlanName and Issue Age
       ReserveName = "20000001"
       IssuingAge = "10"
    
    
    'Creating Table Header
        PlanName = "PlanName"
        Range("G1").Value = PlanName
    
        IssueAge = "IssueAge"
        Range("H1").Value = IssueAge
    
        Duration = "Duration"
        Range("I1").Value = Duration
    
        Factor = "Factor"
        Range("J1").Value = Factor
    
    'Creating Duration, IssueAge, & PlanName Inputs
        x = 1
        While x < 101
        PlanNameAddress = "G" + VBA.Trim(Str(x + 1))
        IssueNameAddress = "H" + VBA.Trim(Str(x + 1))
        DurationAddress = "I" + VBA.Trim(Str(x + 1))
        Range(DurationAddress).Value = x
        x = x + 1
        Range(PlanNameAddress).Value = ReserveName
        Range(IssueNameAddress).Value = IssuingAge
        Wend
    
    
    'Selects TermReserve
    Set TermReserve = Range("A1:E869")
    TermReserve.Select
    
    'Inputs for Factor Table
    Range("A3:E3").Copy
    Range("J2").PasteSpecial Transpose:=True
    Range("A4:E4").Copy
    Range("J7").PasteSpecial Transpose:=True
    
    End Sub
    If you look at 'Inputs for Factor Table, I want to be able to do exactly that but on a loop so I don't have to keep coding each specific row.
    I want the loop to stop once it reaches Row 23 which starts a new cycle.

    TerminalReserveMacro.xlsm

    Thank for your responses and help!!!

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Copy and Special Paste Loop

    Try this

    'Inputs for Factor Table
    Dim i As Integer
    Range("J2:J" & Range("J" & Rows.Count).End(xlUp).Row).ClearContents
    For i = 3 To 23
        Range("A" & i, "E" & i).Copy
        Range("J" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Transpose:=True
    Next i
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Registered User
    Join Date
    08-13-2015
    Location
    Houston, Texas
    MS-Off Ver
    2010
    Posts
    61

    Re: Copy and Special Paste Loop

    This works great, but I do have some questions! First, I replaced my section of 'Inputs for Factor Table and put in yours, and it worked magically, but it deleted my column header.

    Second, I attempted to put your code in my loop in 'Creating Duration, IssueAge, and PlanName Inputs, just to see what will happen and if it will work simultaneously, but it loads the factors, but nothing else.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Copy and Special Paste Loop

    but it deleted my column header.
    This should correct that
    'Inputs for Factor Table
    Dim i As Integer
    If Range("J" & rows.Count).end(xlUp).Row > 1 Then Range("J2:J" & Range("J" & Rows.Count).End(xlUp).Row).ClearContents
    For i = 3 To 23
        Range("A" & i, "E" & i).Copy
        Range("J" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Transpose:=True
    Next i
    , I attempted to put your code in my loop in 'Creating Duration, IssueAge, and PlanName Inputs, just to see what will happen and if it will work simultaneously, but it loads the factors, but nothing else.
    I cannot help you with this because I have no idea what you are trying to do.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Copy and Special Paste Loop

    Duplicate thread. Please do not respond in this thread anymore. See http://www.excelforum.com/excel-prog...y-looping.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. copy formula and paste for new data added and autofill.....and paste special values
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-13-2014, 07:40 AM
  2. Loop through Find then special paste background color with VBA
    By andsimon91 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2014, 04:54 PM
  3. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  4. Loop with Paste Special Values, Formats but no Borders
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2012, 10:07 AM
  5. Paste special charts using loop
    By Essec in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2012, 10:13 AM
  6. For next loop and paste special Help please
    By mrdata in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-13-2006, 09:55 PM
  7. [SOLVED] Copying static cells in a loop....Paste Special problems
    By knox5731@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2006, 04:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1