+ Reply to Thread
Results 1 to 5 of 5

Thread: Copy a cell to another sheet N number of times Excel 2007

  1. #1
    Registered User
    Join Date
    05-31-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    2

    Copy a cell to another sheet N number of times Excel 2007

    Guys,

    I've got a small challenge.

    In Sheet1
    Cell A1 = M12345
    Cell B1 = 3
    Cell A2 = Z67890
    Cell B2 = 5

    I need to copy this value of A1 & B2 to Sheet2 number of times mentioned in Cell B1 & B2. Example My output should be:

    M12345
    M12345
    M12345
    Z67890
    Z67890
    Z67890
    Z67890
    Z67890

    Hope you guys could help me on this

    Regards

    Kowshick M Subramaniam

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Copy a cell to another sheet N number of times Excel 2007

    Try this:
    Sub CopyMultiples()
    Dim MyRng As Range, Num As Range, NR As Long
    
    Set MyRng = Sheets("Sheet1").Range("B:B").SpecialCells(xlConstants, xlNumbers)
    
    With Sheets("Sheet2")
        NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
        
        For Each Num In MyRng
            .Range("A" & NR).Resize(Num).Value = Num.Offset(, -1).Value
            NR = NR + Num
        Next Num
    End With
        
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: Copy a cell to another sheet N number of times Excel 2007

    hi kowshick, option, press Start

    Sub test()
    Dim data, result, i As Long, n As Long, j As Long
    
    If Range("a1") = "" Then Exit Sub
    
    With Range("a1", Cells(Rows.Count, "a").End(xlUp))
        data = .Resize(, 2)
        ReDim result(1 To Application.Sum(.Offset(, 1)), 1 To 1)
    End With
    
    For i = 1 To UBound(data)
        If data(i, 1) <> "" Then
            For n = 1 To data(i, 2)
                j = j + 1
                result(j, 1) = data(i, 1)
            Next
        End If
    Next
    
    If j > 0 Then Sheets.Add(after:=Sheets(Sheets.Count)).Range("a1").Resize(j) = result
    
    End Sub
    Attached Files Attached Files
    Last edited by watersev; 12-14-2011 at 05:32 AM.

  4. #4
    Registered User
    Join Date
    05-31-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Copy a cell to another sheet N number of times Excel 2007

    Sorry for the late response. Just came in from work spot.

    Thank you Guys for your help....it really worked wonders for me !!!!

  5. #5
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Copy a cell to another sheet N number of times Excel 2007

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0