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
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 theicon 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!)
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
Last edited by watersev; 12-14-2011 at 05:32 AM.
Sorry for the late response. Just came in from work spot.
Thank you Guys for your help....it really worked wonders for me !!!!
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 theicon 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!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks