Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88126

Create new sheet with name from value of other sheet's cell's value

$
0
0

I have 02 sheets as follows. I want to add new sheets with name predetermined in "Sheet_Name" Column of Sheet " Summarize".

For example: I have entered 03 sheet name " ABC" , "BCC", "XYZ" then 03 sheets will be created with corresponding name. Then I will copy the content of the sheet "Template" to " ABC", "BCC", "XYZ" and change the B1 value of new sheets with its name.

How can I do this with VBA? I have written a snippet for creating but it can not run. Thanks.

Sub Macro2()

    Dim i As Integer
    Dim n As Integer
    n = ThisWorkbook.Sheets(Summary).Range("B2", ActiveCell.End(xlDown)).Count

    For i = 1 To n
        Sheets.Add
        Sheets.Add.Name = ThisWorkbook.Sheets(Summary).Cells(i + 1, B).Value      
    Next i

End Sub

Sheet " Summarize"

enter image description here

Sheet "Template"enter image description here


As per the guide of Bigben, I write these codes to create new sheets but apart from "ABC", "BCC", "XYZ", it created 03 other sheets.

enter image description here

Sub Macro2()

    Dim i As Integer
    Dim n As Integer

    With Sheets("Summary")
        n = .Range("B"& .Rows.Count).End(xlUp).Row - 1
        For i = 1 To n
            Sheets.Add
            Sheets.Add.Name = ThisWorkbook.Sheets("Summary").Cells(i + 1, 2).Value
        Next i
    End With

End Sub

Viewing all articles
Browse latest Browse all 88126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>