VBA Loop from a list to comulms

Summerso1

New Member
Joined
Jul 24, 2014
Messages
45
I I'm looking for a VBA loop that goes down column A and copies the first 7 cells to column C and then the next seven cells from column A to column D and so on. Basically what I'm trying to do is i have a list of data but i want to put them into column rows so they represent weeks.

Thanks for the help!!
 
Code:
Option Explicit


Sub sMakeWeeks()


Dim vDataIn, vDataOut
Dim i As Long, j As Long, k As Long


vDataIn = Range("A1", Range("A" & Rows.Count).End(xlUp))


ReDim vDataOut(1 To 7, 1 To Application.WorksheetFunction.RoundUp(UBound(vDataIn) / 7, 0))


j = 0: k = 1


For i = LBound(vDataIn) To UBound(vDataIn)
    j = j + 1
    If j > 7 Then
        j = 1
        k = k + 1
    End If
    vDataOut(j, k) = vDataIn(i, 1)
Next 'i


Range("C1").Resize(7, Application.WorksheetFunction.RoundUp(UBound(vDataIn) / 7, 0)) = _
    vDataOut


End Sub
 
Upvote 0

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