I have got an issue with multiple values in VBA excel, that I would like to copy and paste in another workbook (or also another worksheet, but not necessarily in this topic).
The point is, that I have got columns D and E with values ranged from row 1 to 366 (D1:D366 and E1:E366) and I have to switch them in cells A5 (column D) and B5 9column E). This is straightforward. However when I add up another commands to copy and paste values, whereas the range of copied cells remains constant and range of cells with paste data changes (increases 30 values every step) I don't know how to make this process quicker. I have made 5 repeatable combinations but I need still 361 another ones.
Is it some more convenient code for this operation?
My code is available here:
Sub jan01()
Range("A5") = ("=D1")
Range("B5") = ("=E1")
Sheets("11_POLAND").Range("AJ60:BY86").Copy
Sheets("13").Range("A1:AP27").PasteSpecial xlPasteValues
End Sub
Sub jan02()
Range("A5") = ("=D2")
Range("B5") = ("=E2")
Sheets("11_POLAND").Range("AJ60:BY86").Copy
Sheets("13").Range("A31:AP57").PasteSpecial xlPasteValues
End Sub
Sub jan03()
Range("A5") = ("=D3")
Range("B5") = ("=E3")
Sheets("11_POLAND").Range("AJ60:BY86").Copy
Sheets("13").Range("A61:AP87").PasteSpecial xlPasteValues
End Sub
Sub jan04()
Range("A5") = ("=D4")
Range("B5") = ("=E4")
Sheets("11_POLAND").Range("AJ60:BY86").Copy
Sheets("13").Range("A91:AP117").PasteSpecial xlPasteValues
End Sub
Sub jan05()
Range("A5") = ("=D5")
Range("B5") = ("=E5")
Sheets("11_POLAND").Range("AJ60:BY86").Copy
Sheets("13").Range("A121:AP147").PasteSpecial xlPasteValues
End Sub
As per the description above the Values for cell A5 and B5 changes one by one. The range for sheet 13 increases every 30 cells down for each simple case. Ultimately I would like to have all copied data one by one without overlapping like in the image attached (zoomed out to show the general purpose). enter image description here To bring all together I used one macro:
Sub january()
Call jan01
Call jan02
Call jan03
Call jan04
Call jan05
End Sub
Anyway the job looks tedious and I believe, that is much quicker solution to solve it? Have someone had issue like this?
Thank you
loop
to perform such an operation, with something like a for loop in VBA, here is a tutorial. This can simplify your code and make it easier to read and operate. – Pierre Chevallier