Solved

creat new tabs tabs

Posted on 2014-08-01
5
197 Views
Last Modified: 2014-08-01
Can an Expert provide me with VBA code that will create a new tab for any items ic column J where the date in column B is Today.

There will be mutiple items in 'J' with the same name but I only want one tab per name.

i.e.

Date      Ref
01/08/2014      CLOVC
01/08/2014      CLOVC
01/08/2014      CLOVC
01/08/2014      BKIDQ
02/08/2014      BKIDQ
02/08/2014      CLOVC
01/08/2014      SUUKG
02/08/2014      MSSU0

So I would tabs created for CLOVC, BKIDQ, SUUKG

Thanks in advance
0
Comment
Question by:Jagwarman
  • 3
  • 2
5 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40233755
Hi,

pls try

Sub macro()

For Each c In Range(Range("J2"), Range("J" & Rows.Count).End(xlUp))
    If c.Offset(0, -9) = Date Then
        On Error Resume Next
        Set Sh = Nothing
        Set Sh = ActiveWorkbook.Worksheets(c.Value)
        On Error GoTo 0
        If Sh Is Nothing Then
            ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
            Worksheets(Worksheets.Count).Name = c.Value
        End If
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:Jagwarman
ID: 40233783
Hi Rgonzo1971

code runs from start to end but no sheets are being created.

When I step through code it looks ok but no tabs????
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40233811
Amended code

Sub macro()

For Each c In Range(Range("J2"), Range("J" & Rows.Count).End(xlUp))
    If c.Offset(0, -8) = Date Then
        On Error Resume Next
        Set Sh = Nothing
        Set Sh = ActiveWorkbook.Worksheets(c.Value)
        On Error GoTo 0
        If Sh Is Nothing Then
            ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
            Worksheets(Worksheets.Count).Name = c.Value
        End If
    End If
Next
End Sub
0
 

Author Comment

by:Jagwarman
ID: 40233822
Brilliant thanks
0
 

Author Comment

by:Jagwarman
ID: 40233832
I have a related question which I am now going to post which is for each tab created I need to put its relative data onto that tab If I had thought about it earlier maybe it could have been one post but this way you get more points :-)   if you respond
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now