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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I don't understand what you're trying to do.
 
Upvote 0
I need the below data to copy 26 times or however many times i place int he Input Box. I also need it to apply an Unit number (190A) to each of the 26 so once the Macro has ran 26 times with 26 Different Unit number i can filter it. All in one spreadsheet. The original spreadsheet Range is "A1", "T189"

1 2 3 4 5
A. Data 1 Data 2 Data 3 Data 4 Data 5
B. Data 2 Data 3 Data 4 Data 5 Data 6
C. Data 3 Data 4 Data 5 Data 6 Data 7
 
Upvote 0
Here is my current Marco: It will not copy 26 . And i cant figure out how to have it read another another Worksheet to apply unit numbers to each of the 26 Copies separately.

Like the first copy lines of 189 in Cell U1 all the well down to U189 = Sheet 2 A1 and so on an so on from Sheet 2 which has 26 Unit Numbers


Sub copy()


Dim rng As Range, i As Integer, n As Long
Dim R As Integer
Set rng = Range("A1", "T189")
R = 189
n = 0
i = InputBox("Enter repetitions")
Do Until n = i + 1
rng.copy Destination:=Range("A" & R + 1)
n = n + 1
R = R * (n + 1)
Loop
End Sub
 
Upvote 0
Maybe this is a better way to say it

In Sheet 1 A1,T189 needs to be copied 26 Times because i have 26 Unit in Sheet 2. Each time in Sheet 1 A1, T189 is copied in Cell U1 down to Cell U189 i need 1 unit to loop for each of the copied data all in Sheet 1
 
Upvote 0
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
 
Upvote 0
That Maybe is dead on it. Thank you so much. Would happen to know the code to add a value to each of the Copies from Sheet 2 A1:A26. Or a easier way.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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