I am attempting to create a macro where I can repeat a range of data 4 times, but changing the value in one column in each instance of repetition. Example-
Current Data:
Col A | Col B | Col C |
------ | ------ | ------ |
data a1 |constant | data c1|
data a2 |constant | data c2|
Expected Data:
Col A | Col B | Col C |
------ | ------ | ------ |
data a1 |constant | data c1|
data a2 |constant | data c2|
data a1 |constantx| data c1|
data a2 |constantx| data c2|
data a1 |constanty| data c1|
data a2 |constanty| data c2|
data a1 |constantz| data c1|
data a2 |constantz| data c2|
I have to do this for multiple files and the data is present in more than 1 row.Each file will have different number of rows that will contain data to copy.
I am able to repeat the data using the below code(for any umber of rows), but I am not able to change the values in middle column. Any help would be greatly appreciated.
Sub Macro1()
Dim lRow As Long
Range("A1").Select
lRow = Cells(Rows.Count, 1).End(xlUp).Row
If lRow = 2 Then
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
End Sub
You can put your input in below ways
or 3
if your input is like below
and number of time reapat data = 3
then your output will be
Case 2 :
if your input is like below
code will be