Solved

creat new tabs tabs

Posted on 2014-08-01
5
196 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 48

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 48

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

707 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

18 Experts available now in Live!

Get 1:1 Help Now