Create worksheets from a list of names using VBA in Microsoft Excel

Follow by Email

How to create a worksheet?

For each name, a worksheet is to be created. The respective data is to be copied in the specific sheet.

We write the macro for loops in Excel VBA, do until loop we will use for this problem. Place the code below into the standard module.

Sub AfterNamesCopying()
   Dim wks As Worksheet, wksData As Worksheet
   Dim intRow As Integer, intRowL As Integer
   Dim strSheet As String
   Application.ScreenUpdating = False
   Set wksData = ActiveSheet
   intRow = 1
   On Error Resume Next
   Do Until IsEmpty(wksData.Cells(intRow, 1))
      If Left(wksData.Cells(intRow, 1), 4) = "name" Then
         Set wks = Worksheets(wksData.Cells(intRow, 1).Value)
         If Err > 0 Or wks Is Nothing Then
            Worksheets.Add after:=Worksheets(Worksheets.Count)
            Range("A1") = "Data"
            ActiveSheet.Name = wksData.Cells(intRow, 1)
         End If
      End If
      intRow = intRow + 1
   On Error GoTo 0
   intRow = 1
   Do Until IsEmpty(Cells(intRow, 1))
      If Left(Cells(intRow, 1), 4) = "name" Then
         strSheet = Cells(intRow, 1)
         With Worksheets(strSheet)
            intRowL = .Cells(Rows.Count, 1).End(xlUp).Row + 1
            .Cells(intRowL, 1).Value = Cells(intRow, 1).Value
         End With
      End If
      intRow = intRow + 1
   Application.ScreenUpdating = True
End Sub
Please follow and like us:

One thought on “Create worksheets from a list of names using VBA in Microsoft Excel

  1. Pingback: van cleef alhambra necklace carnelian imitation

Leave a Reply

Your email address will not be published. Required fields are marked *

To avoid automated spam,Please enter the value *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>