Reiterate group of columns based on cell value

barryk0211

New Member
Joined
Feb 18, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I have a start date and end date. For each quarter I want to automatically create a group of columns (L:Q). Once it gets to zero quarter remaining the program ends.

1582016931914.png

1582016888244.png
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi Barry, welcome to the forum. What is your question? In your screenshot you'll have 18 quarters between start date and end date and only 6 columns, what's the idea there?
Thanks for some clarification!
 
Upvote 0
Hi Barry, welcome to the forum. What is your question? In your screenshot you'll have 18 quarters between start date and end date and only 6 columns, what's the idea there?
Thanks for some clarification!
Thank you.

The project is to create a worksheet that automatically adds quarters based on the amount of quarters in the project (cell value). So from columns A through K will be a grand total SUMIF and the rest of the worksheet will be duplicates of columns L:Q (quarter).

So I'd like L:Q repeated based on the cell value in a specific cell.

Let me know if you'd like for me to elaborate, I appreciate the help!
 
Upvote 0
Hi Barry,
that does make a bit more sense :). So you probably are looking for some VBA code to copy column L:Q and paste it after your current data. Hereby some code to get you started. Macro1 is the one I recorded copy-inserting columns C:E and CopyMeNTimes is the macro I created using a bit of that code.
VBA Code:
Sub Macro1()
'
' Macro1 Macro

    Columns("C:E").Select
    Selection.Copy
    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight
    Columns("C:E").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("I:I").Select
    Selection.Insert Shift:=xlToRight
    Range("C1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "1"
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "2"
    Range("I1").Select
    ActiveCell.FormulaR1C1 = "3"
    Range("G6").Select
End Sub


Sub CopyMeNTimes()

n = Range("B1").Value

If n > 0 Then
    For c = 1 To n
        Columns("C:E").Copy
        Columns("F:F").Insert Shift:=xlToRight
        Range("C1").Offset(0, c * 3).Value = c
        Application.CutCopyMode = False
    Next c
End If

End Sub
Hope that gets you started, if you want to learn some more VBA, try e.g. Free VBA Training Course
Cheers
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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