Paste values number of times based off count in specific cell

nidg

New Member
Joined
Sep 11, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I'm trying to paste a value from one cell into another column a number of times. The number of times the value will be copied is determined by a counter. I have thousands of these values that I want to do this for which is why i need a quick way to do it.

Would love some suggestions. Thanks
 

Attachments

  • copypastevcolumn.PNG
    copypastevcolumn.PNG
    9.6 KB · Views: 15

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I'm sure there'll be a way of doing this with functions (I note you have 365) but here's a VBA method. Change the assumptions as marked in the code.
VBA Code:
Option Explicit
Sub nidg()
    Dim ws As Worksheet, rng As Range
    Dim LCol As Long, TotRows As Long, TotCols As Long
    Set ws = Worksheets("Sheet1")                           '<-- *** Change to actual sheet name ***
    LCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
    Set rng = ws.Range(ws.Cells(1, 3), ws.Cells(2, LCol))   '<-- *** Assumes first cell is C1 ***
    TotRows = Application.Sum(rng.Rows(2))
    TotCols = rng.Columns.Count
    
    Dim a, b, i As Long, j As Long, k As Long
    ReDim a(1 To TotRows, 1 To 1)
    b = rng
    k = 1
    For i = 1 To TotCols
        For j = 1 To b(2, i)
            a(k, 1) = b(1, i)
            k = k + 1
        Next j
    Next i
    ws.Range("C5").Resize(UBound(a, 1), 1).Value = a        '<-- *** Assumes destination cell is C5 ***
End Sub

Before:
nidg.xlsm
CDEF
118/11/202320/11/202321/11/202322/11/2023
26123
3
4
5
6
Sheet1


After:
nidg.xlsm
CDEF
118/11/202320/11/202321/11/202322/11/2023
26123
3
4
518/11/2023
618/11/2023
718/11/2023
818/11/2023
918/11/2023
1018/11/2023
1120/11/2023
1221/11/2023
1321/11/2023
1422/11/2023
1522/11/2023
1622/11/2023
17
Sheet1
 
Upvote 0
Hi & welcome to MrExcel.
A formula option
Fluff.xlsm
ABCDEF
118/11/202320/11/202321/11/202322/11/2023
26123
3
4
518/11/2023
618/11/2023
718/11/2023
818/11/2023
918/11/2023
1018/11/2023
1120/11/2023
1221/11/2023
1321/11/2023
1422/11/2023
1522/11/2023
1622/11/2023
17
Sheet7
Cell Formulas
RangeFormula
C5:C16C5=TOCOL(IF(SEQUENCE(MAX(C2:F2))<=C2:F2,C1:F1,1/0),2,1)
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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