PDA

View Full Version : [SOLVED:] Copy Values from an array into sheet tab names



pedrostur
04-06-2016, 04:00 AM
Greetings,

I wanted to ask you if there is any VBA code that allows to copy the values (names or number for example) from an array (A3:A107 for example) to each excel sheet tab. To illustrate in simpler terms, if I have a column with A, B and C in each row as values, I want 3 sheets with names A, B and C respectively.

Thanks for your attention and thanks in advance.

pedrostur
04-06-2016, 04:15 AM
I would like to add that it would be optimal to find a way to do this instantly (by creating a button maybe) for 100 values into worksheet tabs

mancubus
04-06-2016, 06:37 AM
welcome to vbax!

upload (see my signature) your workbook as is and include the output by manually doing what the vba procedure will do.

Paul_Hossler
04-06-2016, 07:00 AM
I'd probably do something along these lines.

It goes down column A in a worksheet named "Master" and tries to add a new WS for each cell




Option Explicit

Sub AddWorksheets()

Dim rName As Range
Dim iErrorCount As Long

For Each rName In Worksheets("Master").Cells(1, 1).CurrentRegion.Columns(1).Cells

'delete it if it's there
On Error Resume Next
Application.DisplayAlerts = False
Worksheets(rName.Value).Delete
Application.DisplayAlerts = True
On Error GoTo 0

On Error GoTo CannotAddForSomeReason
Worksheets.Add.Name = rName.Value
Next

If iErrorCount = 0 Then
Call MsgBox("All Done", vbInformation + vbOKOnly, "Add Worksheets")
ElseIf iErrorCount = 1 Then
Call MsgBox("All Done, only 1 error", vbInformation + vbOKOnly, "Add Worksheets")
Else
Call MsgBox("All Done, but with " & iErrorCount & " errors", vbInformation + vbOKOnly, "Add Worksheets")
End If

Exit Sub

CannotAddForSomeReason:
Call MsgBox("Sorry, but cannot add " & rName.Text, vbCritical + vbOKOnly, "Add Worksheets")
iErrorCount = iErrorCount + 1

'delete the one that was added since it's no good
On Error Resume Next
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
On Error GoTo 0

Resume Next
End Sub

pedrostur
04-06-2016, 10:06 AM
Thank you so much! It fitted perfectly. I am happy I joined this forum. This really cleared some of my doubts. Thank you again for your time.