View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ben McClave Ben McClave is offline
external usenet poster
 
Posts: 173
Default VBA Macro to Create Sheets Based on Column of Values

Good Afternoon,

This code worked for me on your sample workbook. It uses an input box to have the user select a range with the Carrier names rather than using the ActiveCell approach. This helps ensure that your are running the code only on those cells that you want to create tabs for. Still, it will end the sub upon encountering a "0", so feel free to select the entire range you need if you wish.

To use this, just paste the code below to a module in your sheet. Hope this helps.

Ben

Option Explicit

Sub ParseCarriers()
Dim rCell As Range
Dim rCarriers As Range
Dim wsNew As Worksheet
Dim wsCarriers As Worksheet

On Error Resume Next
Set rCarriers = Application.InputBox("Please select the range of Carrier names to add", "Carrier Selection", , , , , , 8)
If rCarriers Is Nothing Then Exit Sub
On Error GoTo 0

Set wsCarriers = Sheets("Carrier Specific")
Application.ScreenUpdating = False

For Each rCell In rCarriers
If rCell.Value = 0 Then GoTo ExitHere
wsCarriers.Copy After:=Sheets(Sheets.Count)
Set wsNew = ActiveSheet
On Error Resume Next
wsNew.Name = rCell.Value
On Error GoTo 0
wsNew.Range("D1").Value = rCell.Value
Next rCell

ExitHe
Application.ScreenUpdating = True
End Sub