ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Duplicate entry "x" number of times (https://www.excelbanter.com/excel-discussion-misc-queries/82137-duplicate-entry-x-number-times.html)

gennario

Duplicate entry "x" number of times
 
Here is my dilemma. I have an entry in column A. I need this entry duplicates
the amount of times by the number in column b (if column b was 20 would
populate the entry from column A in columns c-v). I have about 50 rows that I
need duplicated and some need to be done 3 times and others 70 times. How can
this be done?

Dave Peterson

Duplicate entry "x" number of times
 
Maybe just a small macro:

Option Explicit
Sub testme()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim HowMany As Variant

With Worksheets("sheet1")
FirstRow = 1 'no headers in row 1?
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
'minor validation here
HowMany = .Cells(iRow, "B").Value
If IsNumeric(HowMany) Then
.Cells(iRow, "C").Resize(1, HowMany) = .Cells(iRow, "A").Value
End If
Next iRow
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

gennario wrote:

Here is my dilemma. I have an entry in column A. I need this entry duplicates
the amount of times by the number in column b (if column b was 20 would
populate the entry from column A in columns c-v). I have about 50 rows that I
need duplicated and some need to be done 3 times and others 70 times. How can
this be done?


--

Dave Peterson


All times are GMT +1. The time now is 12:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com