Copy and paste Multiple times based on cell value

thomsonreuters

New Member
Joined
Dec 9, 2017
Messages
26
Hi
I want to copy and paste range of cells multiple times based on specific value mention in the cells.
The problem is want to paste range of cells difference time...pls see below, it will give more clarity...its very urgent...pls pls help me someone...column A copy range and colum B no.of time copy and past....Column C is what I want to do..
Colum A Column B Column C
ABCD 2 ABCD
FGHI 1 FGHI
KLMN 3 KLMN
PQRS 3 PQRS
ABCD
KLMN
PQRS
KLMN
PQRS
Copy and paste should be range of cells, not like same cells pasted multiple time again and again continuously....

Pls help on this

Thanks
JP
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this:

VBA Code:
'https://www.mrexcel.com/board/threads/copy-and-paste-multiple-times-based-on-cell-value.1133775
Option Explicit
Sub Macro1()

    Dim lngMyRow As Long
    Dim lngPasteRow As Long
    
    Application.ScreenUpdating = False
    
    For lngMyRow = 2 To Cells(Rows.Count, "A").End(xlUp).Row 'Starts from Row 2. Change to suit.
        lngPasteRow = Cells(Rows.Count, "C").End(xlUp).Row + 1
        Cells(lngPasteRow, "C").Resize(Cells(lngMyRow, "B")).Value = Cells(lngMyRow, "A")
    Next lngMyRow

    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Try this:

VBA Code:
'https://www.mrexcel.com/board/threads/copy-and-paste-multiple-times-based-on-cell-value.1133775
Option Explicit
Sub Macro1()

    Dim lngMyRow As Long
    Dim lngPasteRow As Long
   
    Application.ScreenUpdating = False
   
    For lngMyRow = 2 To Cells(Rows.Count, "A").End(xlUp).Row 'Starts from Row 2. Change to suit.
        lngPasteRow = Cells(Rows.Count, "C").End(xlUp).Row + 1
        Cells(lngPasteRow, "C").Resize(Cells(lngMyRow, "B")).Value = Cells(lngMyRow, "A")
    Next lngMyRow

    Application.ScreenUpdating = True

End Sub

Regards,

Robert


Thanks much Robert, but this is not what i am required

i want like below

From your codeMy Requirement
ABCDABCD
ABCDFGHI
FGHIKLMN
KLMNPQRS
KLMNABCD
KLMNKLMN
PQRSPQRS
PQRSKLMN
PQRSPQRS

same text should not be repeat continuously.....hope you understand...

advance thanks for your help on this...

thanks
JP
 
Upvote 0
Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim i As Long
    Dim lngMyRow As Long, lngLastRow As Long, lngPasteRow As Long
    
    'The code assumes the following:
    '1. Numbers for output text are in Col. B
    '2. Text to be outputted are in Col. C
    '3. Output will be the next avaliable row in Col. A
    
    Application.ScreenUpdating = False
    
    lngLastRow = Range("B:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For i = 1 To Evaluate("MAX(B:B)")
        For lngMyRow = 2 To lngLastRow
            If Range("B" & lngMyRow).Value >= i Then
                lngPasteRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
                Range("A" & lngPasteRow).Value = Range("C" & lngMyRow).Value
            End If
        Next lngMyRow
    Next i
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim i As Long
    Dim lngMyRow As Long, lngLastRow As Long, lngPasteRow As Long
   
    'The code assumes the following:
    '1. Numbers for output text are in Col. B
    '2. Text to be outputted are in Col. C
    '3. Output will be the next avaliable row in Col. A
   
    Application.ScreenUpdating = False
   
    lngLastRow = Range("B:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
   
    For i = 1 To Evaluate("MAX(B:B)")
        For lngMyRow = 2 To lngLastRow
            If Range("B" & lngMyRow).Value >= i Then
                lngPasteRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
                Range("A" & lngPasteRow).Value = Range("C" & lngMyRow).Value
            End If
        Next lngMyRow
    Next i
   
    Application.ScreenUpdating = True

End Sub

WooooooW Robert....it's working fine. Thank u so much...

Will post again if i need any help

thanks
JP
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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