• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help with Prepopulating New Sheets for an Excel Dummy

talianm

New Member
I'm trying to prepopulate a new tab with designated numbers of rows based on input from a previous tab's cell.
Example, on Sheet2 I have a heading in Column A "Number of Cycles" (A1); "Number of Days in Cycle" (B2)
In A2, 15; In B2, 28

I want 15 rows labeled Cycle 1, Cycle 2, etc. in Column A on a new tab (Sheet3) with 28 rows in between each Cycle.

Is there anyway to do this?
 
Welcome to the forums!

You didn't indicate whether you want to use VBA or formulas...so I've done both.

The VBA uses this code:

Code:
Sub BuildTab()

Dim No_Cycles As Integer
    No_Cycles = Sheets("Sheet2").Range("$A$2").Value

Dim Days_Per As Integer
    Days_Per = Sheets("Sheet2").Range("$B$2").Value

Dim cyclecounter As Integer

Sheets.Add After:=Sheets(Sheets.Count)

For cyclecounter = 1 To No_Cycles

    Sheets(Sheets.Count).Range("$A$2:$A$" & Days_Per + 1).Offset((cyclecounter - 1) * Days_Per, 0).Value = "Cycle " & cyclecounter
 
Next

End Sub

The formula generates a number only, then I've customized the number format (Ctrl+1) to add the word "Cycle" to the cells.

=IF(ROW()<Sheet2!$A$2*Sheet2!$B$2,IF(COUNTIF($A$1:A1,A1)<Sheet2!$B$2,A1,A1+1),"")

Take a look at the attached spreadsheets, see if either of them will work.
 

Attachments

  • talianm-formula.xlsx
    27.7 KB · Views: 3
  • talianm-vba.xlsm
    17.7 KB · Views: 2
Back
Top