VBA - how to repeat a set number of values X times
Closed
NELM
-
Jun 10, 2018 at 03:18 AM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Jun 10, 2018 at 04:53 AM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Jun 10, 2018 at 04:53 AM
Related:
- VBA - how to repeat a set number of values X times
- How to set whatsapp time - Guide
- Vba case like - Guide
- How to set auto redial on android - Guide
- Number to words in excel formula without vba - Guide
- How to set out of office in outlook - Guide
1 response
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
Jun 10, 2018 at 04:53 AM
Jun 10, 2018 at 04:53 AM
Hello Nelm,
Try the following code, placed in a standard module and assigned to a button:-
The code assumes that the values to copy are in Column A starting in row2 with a heading in row1. The values are copied to Column C (x times) based on the number placed in the Input Box that appears on clicking on the button.
Following is the link to a little sample that I have prepared showing how the code works:-
http://ge.tt/40wBy6q2
Click on the "RUN" button . When the Input Box appears, enter the number of times (1, 2, 3 etc....) you wish to copy the Column A data and then click on OK.
I hope that this helps.
Cheerio,
vcoolio.
Try the following code, placed in a standard module and assigned to a button:-
Sub CopySelection() Dim lr As Long, i As Integer Dim SCT As String lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row SCT = InputBox("Please enter the number of times to copy data.") If SCT = vbNullString Then Exit Sub Application.ScreenUpdating = False For i = 1 To SCT Sheet1.Range("A2:A" & lr).Copy Sheet1.Range("C" & Rows.Count).End(3)(2) Next i Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
The code assumes that the values to copy are in Column A starting in row2 with a heading in row1. The values are copied to Column C (x times) based on the number placed in the Input Box that appears on clicking on the button.
Following is the link to a little sample that I have prepared showing how the code works:-
http://ge.tt/40wBy6q2
Click on the "RUN" button . When the Input Box appears, enter the number of times (1, 2, 3 etc....) you wish to copy the Column A data and then click on OK.
I hope that this helps.
Cheerio,
vcoolio.