Repeated cells in same column VBA

grifdoogindoggy

New Member
Joined
Aug 27, 2019
Messages
21
I am struggling to create a simple loop that will allow me to repeat a cell value down a column for a number of my choosing.

I want to turn this:
A1
A2
A3

Into this ("2", for example):
A1
A1
A2
A2
A3
A3

Anything helps! Thank you.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:
Code:
Sub M1()

    Dim v   As Variant
    Dim x   As Long
    Dim i   As Long
    
    x = InputBox("Enter repetition value: ")
    v = Cells(1, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row).Value
    
    Application.ScreenUpdating = False
    
    If x > 1 Then
        For i = 2 To x
            Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(v, 1)).Value = v
        Next i
        Cells(1, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row).Sort key1:=Cells(1, 1), order1:=xlAscending
    End If
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
Try:
Code:
Sub M1()

    Dim v   As Variant
    Dim x   As Long
    Dim i   As Long
    
    x = InputBox("Enter repetition value: ")
    v = Cells(1, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row).Value
    
    Application.ScreenUpdating = False
    
    If x > 1 Then
        For i = 2 To x
            Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(v, 1)).Value = v
        Next i
        Cells(1, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row).Sort key1:=Cells(1, 1), order1:=xlAscending
    End If
    
    Application.ScreenUpdating = True
    
End Sub

How would I print this to a new sheet?
 
Upvote 0
Change parts in red to suit:
Rich (BB code):
Sub M1()

    Dim v   As Variant
    Dim x   As Long
    Dim i   As Long
    
    Dim srcSheet    As Worksheet
    Dim destSheet   As Worksheet
    
    Set srcSheet = Sheets("Source")
    Set destSheet = Sheets("Destination")
    
    x = InputBox("Enter repetition value: ")
    v = srcSheet.Cells(1, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row).Value
    
    Application.ScreenUpdating = False
    
    If x > 1 Then
        With destSheet
            For i = 2 To x
                .Cells(.Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(v, 1)).Value = v
            Next i
            .Cells(1, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row).Sort key1:=Cells(1, 1), order1:=xlAscending
        End With
    End If
    
    Application.ScreenUpdating = True
    
    Set srcSheet = Nothing: Set destSheet = Nothing
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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