0

I am trying to create a for loop that reformats a data table into columns. It's a simple copy and paste, however, I am having trouble getting the vba to move on to the next section. It is starting in cell F5 copying down and I want to paste it into a new sheet in cell B2 and have it repeat the process for cells G5, E5, and so on. Also, I want it to copy the date, paste it into the new sheet in cell C2 and have it be the same row length as the data it copies from cells F5, G5, E5, and so on.

enter image description here enter image description here

Option Explicit

Sub formatData()
Dim i As Integer
Dim r As Integer
Dim j As Integer
Dim k As Integer
Dim l As Range
Dim f As Range

i = Range("F5").End(xlToRight).Column
k = Range("B5").End(xlDown).Row




'Regular For loop
For r = 6 To i
Sheets("FCST").Select
Range("F5").Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets("reFormFCST").Select
Range("B3").PasteSpecial


'Dates For Loop
For j = 5 To k
Sheets("FCST").Select

Sheets("reFormFCST").Select



Next


Next

End Sub
  • First step: [How to avoid Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) – Cameron Critchlow Feb 14 '23 at 21:29
  • Looks like a "depivot"/"unpivot" operation? Some previous posts here if you search on those terms. Eg: https://stackoverflow.com/questions/36365839/transpose-multiple-columns-to-multiple-rows-with-vba/36366394#36366394 – Tim Williams Feb 15 '23 at 17:16

0 Answers0