PC Review


Reply
Thread Tools Rate Thread

Copy and pasting based on criteria

 
 
haas786@yahoo.com
Guest
Posts: n/a
 
      8th Feb 2008
Hi all!

You guys are very helpful and I was wondering if I can get some more
assistance. In cells A5 to A12, I have names of people (no
duplicates.) In cells B5 to B12 I have numbers next to the names. I
need to write a code which will start by allowing me to look at the
number in B5 and copy the name in A5 and start pasting it in cell D15
and then D16 and so on (down the row) as many times as represented by
the number in cell B5. Then, the code should look at cell B6 and
depending on the number in there, start pasting the name in A6 that
many times in whichever cell in column is next empty. The code will
stop as soon as it encounters a 0 value in any cell in B5 to B12.

For the purposes of an example, please see the following:
A B
Dave 4
John 3
Brad 2
Jack 0
Jane 0
Bart 0
Kate 0
Kent 0

The code will essentially copy Dave first, and then paste it 4 times
in cells D15, D16, D17, and D18. Next, it will copy John 3 times and
paste it in D19, D20, and D21. Next it will go to Brad, and copy it 2
times, and paste it in D22 and D23. Next, it will go to Jack, and the
code will stop there becaus eit encounters a 0.

I hope the example helps illustrate what i need. If you have any
questions, please don't hesitate to ask.

Thanks in advance for all your help!
 
Reply With Quote
 
 
 
 
Gleam
Guest
Posts: n/a
 
      8th Feb 2008
Please try this:
Option Explicit
Sub CopyNames()
Dim i1 As Integer, Name As String, n1 As Integer, p1 As Integer, j1 As
Integer
p1 = 15
For i1 = 5 To 12 Step 1
Name = Cells(i1, 1).Value
n1 = Cells(i1, 2).Value
If n1 = 0 Then
MsgBox "Zero found. Stopping."
Exit Sub
End If
For j1 = p1 To p1 + n1 - 1 Step 1
Cells(j1, 4).Value = Name
Next j1
p1 = p1 + n1 - 1
Next i1
End Sub


"(E-Mail Removed)" wrote:

> Hi all!
>
> You guys are very helpful and I was wondering if I can get some more
> assistance. In cells A5 to A12, I have names of people (no
> duplicates.) In cells B5 to B12 I have numbers next to the names. I
> need to write a code which will start by allowing me to look at the
> number in B5 and copy the name in A5 and start pasting it in cell D15
> and then D16 and so on (down the row) as many times as represented by
> the number in cell B5. Then, the code should look at cell B6 and
> depending on the number in there, start pasting the name in A6 that
> many times in whichever cell in column is next empty. The code will
> stop as soon as it encounters a 0 value in any cell in B5 to B12.
>
> For the purposes of an example, please see the following:
> A B
> Dave 4
> John 3
> Brad 2
> Jack 0
> Jane 0
> Bart 0
> Kate 0
> Kent 0
>
> The code will essentially copy Dave first, and then paste it 4 times
> in cells D15, D16, D17, and D18. Next, it will copy John 3 times and
> paste it in D19, D20, and D21. Next it will go to Brad, and copy it 2
> times, and paste it in D22 and D23. Next, it will go to Jack, and the
> code will stop there becaus eit encounters a 0.
>
> I hope the example helps illustrate what i need. If you have any
> questions, please don't hesitate to ask.
>
> Thanks in advance for all your help!
>

 
Reply With Quote
 
Gleam
Guest
Posts: n/a
 
      8th Feb 2008
Ooops!
Line should read: p1 = p1 + n1

Gleam

"(E-Mail Removed)" wrote:

> Hi all!
>
> You guys are very helpful and I was wondering if I can get some more
> assistance. In cells A5 to A12, I have names of people (no
> duplicates.) In cells B5 to B12 I have numbers next to the names. I
> need to write a code which will start by allowing me to look at the
> number in B5 and copy the name in A5 and start pasting it in cell D15
> and then D16 and so on (down the row) as many times as represented by
> the number in cell B5. Then, the code should look at cell B6 and
> depending on the number in there, start pasting the name in A6 that
> many times in whichever cell in column is next empty. The code will
> stop as soon as it encounters a 0 value in any cell in B5 to B12.
>
> For the purposes of an example, please see the following:
> A B
> Dave 4
> John 3
> Brad 2
> Jack 0
> Jane 0
> Bart 0
> Kate 0
> Kent 0
>
> The code will essentially copy Dave first, and then paste it 4 times
> in cells D15, D16, D17, and D18. Next, it will copy John 3 times and
> paste it in D19, D20, and D21. Next it will go to Brad, and copy it 2
> times, and paste it in D22 and D23. Next, it will go to Jack, and the
> code will stop there becaus eit encounters a 0.
>
> I hope the example helps illustrate what i need. If you have any
> questions, please don't hesitate to ask.
>
> Thanks in advance for all your help!
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy and Paste based on criteria stacia Microsoft Excel Programming 1 12th Feb 2010 05:42 PM
Copy Cells Based on Criteria in VBA bugsyb6 Microsoft Excel Programming 3 4th Feb 2009 02:09 PM
Macro for copying and pasting values based on criteria Leigh Douglass Microsoft Excel Programming 3 28th Jan 2008 04:34 PM
Copy/Paste based on Criteria Dan R. Microsoft Excel Programming 2 5th Feb 2007 08:25 PM
Filter/copy based on criteria gavmer Microsoft Excel Programming 0 5th Oct 2004 12:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:10 AM.