+ Reply to Thread
Results 1 to 5 of 5

How to create a loop?

  1. #1
    Registered User
    Join Date
    12-15-2014
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    19

    How to create a loop?

    Hi,

    I am new on this forum and I hope it will help me learn VBA. I have some data that I would like to copy from 'ws1' to 'ws2'. The data in 'ws1' is displayed in rows, and I would like to paste it to 'ws2' in column D. Below is the code I wrote for the first row of data. I would like to repeat this for every row - I have 104 rows. Can someone help me figure out how to loop this? Thanks so much!

    Sub copypaste()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim i As Integer

    i = 3


    Set ws1 = Sheets("profits_raw")

    Set ws2 = Sheets("panel_US")

    ws1.Activate
    ws1.Range(Cells(i, 2), Cells(i, 17)).Copy

    ws2.Activate

    ws2.Range(Cells(i, 4), Cells(i, 4)).PasteSpecial Transpose:=True

    'ws2.Range("D2:D17").PasteSpecial Transpose:=True



    End Sub

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to create a loop?

    Welcome to the Forum. Please review the Forum Rules pay specific attention to Rule No. 3 about posting code.

    http://www.excelforum.com/forum-rule...rum-rules.html

    Try:

    Please Login or Register  to view this content.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,528

    Re: How to create a loop?

    With a loop ...

    Please Login or Register  to view this content.

    Without a loop ...
    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    12-15-2014
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: How to create a loop?

    Thank you all for your help!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,528

    Re: How to create a loop?

    You're welcome. Thanks for the rep.

+ 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. How to create this loop in VBA
    By carpekd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-01-2014, 07:34 PM
  2. [SOLVED] Create a loop with VBA
    By DeNam in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-09-2013, 04:20 AM
  3. Help create a loop
    By moshro1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2013, 04:04 AM
  4. Create a Loop
    By elfvis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-10-2012, 06:13 PM
  5. [SOLVED] How do I create a For loop within a For loop?
    By Linking to specific cells in p in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-24-2005, 06:07 AM

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