Results 1 to 18 of 18

Copy a table data "x" number of times to another sheet

Threaded View

  1. #1
    Registered User
    Join Date
    10-16-2009
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    31

    Thumbs up Copy a table data "x" number of times to another sheet

    I have a excel table in Cell B2:C2 to B10:C10 in sheet1. I need to copy this table "x" number of times as specifiedin A2, with an row offset (gap) of 10 rows starting D2 in sheet2.
    But somehow, only the first row of the data is getting copied???

    I have the following macro:
    Sub CopyPaste()
     
     
        Dim LRow As Integer
        Dim LQty As Integer
        Dim LProduct As String
        Dim LColEPosition As Integer
        Dim j As Integer
        Dim LStart As Integer
        Dim LEnd As Integer
     
        'Search for values in column B starting at row 2
        LRow = 2
     
        'Copy values to column E starting at row 2
        LColEPosition = 2
        'LColEPosition = ActiveCell.Offset(rowOffset:=3, columnOffset:=3).Activate
     
        'Search through values in column B until a blank cell is encountered
        While Len(Range("B" & CStr(LRow)).Value) > 0
     
            'Retrieve quantity and product name
            LQty = Range("A" & CStr(LRow)).Value
            LProduct = Range("B" & CStr(LRow)).Value
     
            'Set start and end position for copy to column E
            LStart = LColEPosition
            LEnd = LColEPosition + LQty
     
            'Copy product name the number of times that is given by the quantity
            For j = LStart To LEnd - 1
                Range("E" & CStr(j)).Value = LProduct
            Next
     
            'Update column E position
            LColEPosition = LEnd
            LRow = LRow + 1
     
        Wend
    End Sub
    Pl help.....
    Attached Files Attached Files
    Last edited by rkayasth; 10-20-2009 at 04:10 AM. Reason: add code tags

Thread Information

Users Browsing this Thread

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

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