Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Copy and pasting based on criteria

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Copy and pasting based on criteria

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


" 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!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Copy and pasting based on criteria

Ooops!
Line should read: p1 = p1 + n1

Gleam

" 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for copying and pasting values based on criteria Leigh Douglass[_2_] Excel Programming 3 January 28th 08 04:34 PM
Copy Row to worksheet based on criteria JoePineapples Excel Discussion (Misc queries) 1 March 7th 07 09:05 AM
Copy/Paste based on Criteria Dan R. Excel Programming 2 February 5th 07 08:25 PM
Filter/copy based on criteria gavmer[_86_] Excel Programming 0 October 5th 04 12:32 AM
Filter/copy based on criteria gavmer[_84_] Excel Programming 0 October 1st 04 03:14 AM


All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"