VBA Input Box

GCLIFTON

Board Regular
Joined
Feb 11, 2016
Messages
60
Question: I need help. I am trying to write a VBA to Copy Set rng = Range("A1", "T189") 26, or 27 or 30 times by using the InputBox("Enter repetitions") and it is not working. All in one worksheet. Can anyone help me with that Code
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Maybe ...

Code:
Sub copy()
  Dim rng As Range
  Dim i As Long
  
  Set rng = Range("A1:T189")
  For i = 1 To InputBox("Enter repetitions")
    rng.copy rng.Offset(rng.Rows.Count * i)
  Next i
End Sub
You can do that without using a loop...
Code:
Sub Copy()
  Dim Rng As Range
  Set Rng = Range("A1:T189")
  Rng.Copy Rng.Resize(Rng.Rows.Count * (1 + InputBox("Enter repetitions")))
End Sub
 
Upvote 0
Clifton, I leave you in Rick's capable hands.
 
Upvote 0
Clifton, I leave you in Rick's capable hands.
@shg,

Your hands are more than capable enough (all I was doing was pointing out a simplification). Anyway, I too do not understand Clifton's question from Message #10.


@Clifton,

What does Sheet2!A1:A26 have to do with the repeated Range A1:T189? And what value are you trying to "add" and where are you trying to add it at?
 
Upvote 0
So Sheet 2 tells how many times the data will be duplicate. So i have in Sheet 2. Each one needs the copied data of 189 applied to it all in Sheet 1

[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: right"]101[/TD]
[/TR]
[TR]
[TD="align: right"]102[/TD]
[/TR]
[TR]
[TD="align: right"]103[/TD]
[/TR]
[TR]
[TD="align: right"]104[/TD]
[/TR]
[TR]
[TD="align: right"]105[/TD]
[/TR]
[TR]
[TD="align: right"]106[/TD]
[/TR]
[TR]
[TD="align: right"]107[/TD]
[/TR]
[TR]
[TD="align: right"]108[/TD]
[/TR]
[TR]
[TD="align: right"]201[/TD]
[/TR]
[TR]
[TD="align: right"]202[/TD]
[/TR]
[TR]
[TD="align: right"]203[/TD]
[/TR]
[TR]
[TD="align: right"]204[/TD]
[/TR]
[TR]
[TD="align: right"]205[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
I forgot to answer the 2nd part of your question, Those units number above would just need to be applied in Cell U or any other cell behind T. So that there is a relationship to each copied data so i can eventually filter by Unit #
 
Upvote 0
So Sheet 2 tells how many times the data will be duplicate. So i have in Sheet 2. Each one needs the copied data of 189 applied to it all in Sheet 1

[TABLE="class: cms_table, width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]101[/TD]
[/TR]
[TR]
[TD="align: right"]102[/TD]
[/TR]
[TR]
[TD="align: right"]103[/TD]
[/TR]
[TR]
[TD="align: right"]104[/TD]
[/TR]
[TR]
[TD="align: right"]105[/TD]
[/TR]
[TR]
[TD="align: right"]106[/TD]
[/TR]
[TR]
[TD="align: right"]107[/TD]
[/TR]
[TR]
[TD="align: right"]108[/TD]
[/TR]
[TR]
[TD="align: right"]201[/TD]
[/TR]
[TR]
[TD="align: right"]202[/TD]
[/TR]
[TR]
[TD="align: right"]203[/TD]
[/TR]
[TR]
[TD="align: right"]204[/TD]
[/TR]
[TR]
[TD="align: right"]205[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Hi GCLIFTON,

_It may be best if you go over to the Test Sub Forum and practice posting there first. Here is a Link to it:
Test Here
_ You can Post and Reply as much as you like there and make as many mistakes there as you like, - the Posts there are mostly ignored and deleted after a few days.

_ Try to achieve a good “Before” and “After” picture with reduced test data for both Sheets. Keep it in the form you did in Post # 17 ( See also the links in my signature for Guidelines and alternative ways to post a screen shot that we are able to copy to a Spreadsheet ( Do not post Images please as we cannot copy them ) )

_ Your "Before" should show how everything everywhere looks at the start before any code runs.
_ Your "After" should be filled in by hand by you to reflect exactly what you want the code to do based on all your “Before” data

_ Use just enough data to demonstrate your type of requirement: Normally any code we do for you would then work with little or no modification much more data ( Desensitize or make up your data, but chose it carefully so that all typical scenarios and formats can be considered ).

Alan
 
Last edited:
Upvote 0
Thank you. Today is my first day. I will go to the Test Sub Forum and try that out. Thank you and i apologize if i have caused any trouble.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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