+ Reply to Thread
Results 1 to 5 of 5

Excel VBA: Looping through rows and copy cell values to another worksheet

  1. #1
    Registered User
    Join Date
    11-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    23

    Excel VBA: Looping through rows and copy cell values to another worksheet

    Facing some diffculty in achieving the desired result for my macro. Intention: I have a list of data in sheets(input).column A(the number of rows that has value will vary and hence i created a loop that will run the macro until the activecell is blank). My macro starts from Range(A2) and stretches all the way down column A, it stops only when it hits a blank row

    Desired result for the macro will be to start copying the cell value in sheet(input).Range(A2) paste it to sheet(mywork).Range(B2:B6).

    For example, if "Peter" was the value in cell sheet(input),range(A2) then when the marco runs and paste the value into sheet(mywork) range(B2:B6). ie range B2:B6 will reflect "Peter"

    Then the macros loop back to sheet(input) & copy the next cell value and paste it to range(B7:B10) Example: "Dave" was the value in sheet(input) Range(A3), then "Dave" will be paste into the next 4 rows in sheet(mywork).Range(B7:B10). B7:B10 will reflect "Dave"

    Again repeating the same process goes back to sheet(input) this time range(A4), copys the value goes to sheet(mywork) and paste it into B11:B15.

    Basically the process repeats....

    The macro ends the when the activecell in sheet(input) column A is empty. Urgently seek the advice/assistance from the experts in the forumn. Thanks in advance. Cheers )))

    Sub playmacro()
    Dim xxx As Long, yyy As Long
    ThisWorkbook.Sheets("Input").Range("A2").Activate
    Do While ActiveCell.Value <> ""
    DoEvents
    ActiveCell.Copy
    For xxx = 2 To 350 Step 4
    yyy = xxx + 3
    Worksheets("mywork").Activate
    With ActiveSheet
    .Range(Cells(xxx, 2), Cells(yyy, 2)).PasteSpecial xlPasteValues
    End With
    Next xxx
    ThisWorkbook.Sheets("Input").Select
    ActiveCell.Offset(1, 0).Activate
    Loop
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Excel VBA: Looping through rows and copy cell values to another worksheet

    Please Login or Register  to view this content.

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

    Re: Excel VBA: Looping through rows and copy cell values to another worksheet

    Please adhere to Forum Rule No. 3 when posting
    "3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing."

    Another:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Excel VBA: Looping through rows and copy cell values to another worksheet

    Thanks a lot! I got my solution!

    @John - Will follow from next time.

  5. #5
    Registered User
    Join Date
    06-03-2016
    Location
    Mumbai, India
    MS-Off Ver
    office 2010
    Posts
    1

    Re: Excel VBA: Looping through rows and copy cell values to another worksheet

    Hi I have same problem. I want to copy each code & past it to another sheet's one particular cell. Want to continue this process by pasting 1 by 1 code in another worksheet. Please help me on this

+ 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 rows from one worksheet to another, where column values are the same
    By klauber in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-26-2013, 01:55 PM
  2. Copy cell values (not formulas) from a pair of rows then paste in a new set of rows
    By pelle3988 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-23-2013, 02:49 PM
  3. [SOLVED] Copy rows from one worksheet to another worksheet based on a cell criteria.
    By keneco in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-07-2013, 10:28 AM
  4. [SOLVED] Copy rows from my main worksheet to another worksheet based on data in one cell
    By gcol in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-08-2012, 05:12 AM
  5. Looping and copy/paste specific rows
    By Desi_bhai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2007, 12:50 PM

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