Copy data multiple time below each other based on condition

Mindrage

Board Regular
Joined
Jan 5, 2009
Messages
133
Dear All,

Need some assistance in creating a macro. I have a number count in tab 2 in one cell and based on which i need to have data in 2 cell (same sheet) copied that many time in sheet one below each other in same column. Expample : If i have a count of 5, i need data in 2 cells to be copied 5 times below each other in sheet one.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi

Give this a go, hope I have understood Your Requirements. Can Be put under a command button.

Code:
Private Sub CommandButton1_Click()

Static Counter
Counter = 0
While Counter < Range("a1").Value  'Cell holding number of copies
   ' Counter = Counter + 1
    
    Range("b3:c3").Copy  'Range to be copied
    
  
    
    If Range("b4").Value = "" Then  ' range to where to start copy
    
    Range("b4").PasteSpecial
    
       Counter = Counter + 1
       
    End If
    
    
    
        If Range("b4").Value > "" And Range("b5") = "" Then
    
        Range("b5").PasteSpecial
        Counter = Counter + 1
        End If
        
    
    
             If Range("b4").Value > "" And Range("b5") > "" Then
    
                Range("b4").Select
                Selection.End(xlDown).Select
                Selection.Offset(1, 0).PasteSpecial
              Counter = Counter + 1
             End If
             
Wend
 
End Sub


regards

Kev
 
Upvote 0
Hi

Amendment to previous post, it does not work for values < 3. This sorts it, but is a little messy, there is probably a tidier way.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

Code:
Application.ScreenUpdating = False
Static Counter
Counter = 0
Range("b4:c18").Clear

                If Range("a1").Value = 1 Then
                    Range("k1:l1").Copy  'Range to be copied
                        Range("b4").PasteSpecial
                            Exit Sub
                End If
                        If Range("a1").Value = 2 Then
                            Range("k1:l1").Copy  'Range to be copied
                            Range("b4:b5").PasteSpecial
                                Exit Sub
                        End If
 
While Counter < Range("a1").Value  'Cell holding number of copies
   ' Counter = Counter + 1
    
    Range("k1:l1").Copy  'Range to be copied
    
  
    
    If Range("b4").Value = "" Then  ' range to where to start copy
    
    Range("b4").PasteSpecial
    
       Counter = Counter + 1
       
    End If
    
    
    
        If Range("b4").Value > "" And Range("b5") = "" Then
    
        Range("b5").PasteSpecial
        Counter = Counter + 1
        End If
        
    
    
             If Range("b4").Value > "" And Range("b5") > "" Then
    
                Range("b4").Select
                Selection.End(xlDown).Select
                Selection.Offset(1, 0).PasteSpecial
              Counter = Counter + 1
             End If
             
Wend
 
End Sub


regards
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top