0

To perform the following actions:

  1. Copy a particular "template"-worksheets as many times as the number of cells selected in the master database
  2. Create worksheets (with names) based on the selected range of cells
  3. Based on the name of the newly created worksheet - update one of the cells
  4. Use VLOOKUP functionality to pull other values based on the cell updated in Step 3.

I have the following VBA code:

Sub CreateWorkSheetByRange()
'variable declaration
Dim WorkRng As Range
Dim Ws As Worksheet
Dim arr As Variant
Dim tws As Worksheet
'Start of Program
On Error Resume Next
'Specify the title of the dialog that requests for range
xTitleId = "Select Range"
' Assign template worksheet to a variable
Set tws = Worksheets("template")
' Assign the application.selection function to the variable WorkRng
Set WorkRng = Application.Selection
' Accept input from the user
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
' Create an array of the input values
arr = WorkRng.Value
' The following line is optional
' Application.ScreenUpdating = False
' Create the Worksheet names based on range selected
    For i = 1 To UBound(arr, 1)
        For j = 1 To UBound(arr, 2)
            tws.Copy after:=Worksheets(Sheets.Count)
            Set Ws = Application.ActiveSheet
            Ws.Name = arr(i, j)
        Next
    Next
' Application.ScreenUpdating = True
End Sub

I would like to improve the following things in my code - but do not know how

  1. Want to know if the code is efficient - or bug free
  2. I want to distribute this to a group of engineers - how can I do it. I should not assume that they know how to utilize this code in VBA - is it possible to give this like a executable excel?
heavyd
  • 65,321
Prasanna
  • 4,174

0 Answers0