+ Reply to Thread
Results 1 to 7 of 7

Error handling when creating sheets based on list and hyperlink

Hybrid View

  1. #1
    Registered User
    Join Date
    08-18-2015
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    20

    Error handling when creating sheets based on list and hyperlink

    Hi,

    I am struggling to solve for two issues.
    1) When I use the code below and a name form my list in the master sheet is >31 characters or uses : /\ ..., I get Template(x) as a name. Is there any way to handle the errors by truncating the names and getting rid of the unallowed characters?
    2) I would also like to create an index in another column of the master sheet with the names and hyperlink of the newly created sheets.

    The code I am using to generate the sheets is:
    Sub CreateSheetsFromList()
        Application.ScreenUpdating = False
        Calculate
        Dim projectCell As Range, projectIDcol As Range
        'Dim ws As Worksheet
        
        Set projectIDcol = Sheets("Portfolio Roadmap").Range("D4")
        Set projectIDcol = Range(projectIDcol, projectIDcol.End(xlDown))
        
        For Each projectCell In projectIDcol
          On Error Resume Next
            If IsError(Worksheets(projectCell.Value)) Then
        Sheets("template").Select ' Select the template as the new worksheet to create
        Sheets("template").Copy After:=Sheets(Sheets.Count) 'Creates a new worksheet based on the template. Worksheet will be named template(1), (2) ect....
        Sheets(Sheets.Count).Name = projectCell.Value ' Renames the worksheets from the index of project.
        
        End If
         
    Next projectCell
    Application.ScreenUpdating = True
    Sheets("Portfolio Roadmap").Select
    Calculate
    End Sub
    Thank you very much for your help,

    Kind regards,

    Guillaume

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Error handling when creating sheets based on list and hyperlink

    1) Add this function to your module, it does what it says it does, you can see in the code where you list the character to remove:
    Function removeSpecial(sInput As String) As String
    Dim sSpecialChars As String, i As Long
        
        sSpecialChars = "\/:*?™""®<>|.&@#(_+`©~);-+=^$!,'"             'This is your list of characters to be removed
        For i = 1 To Len(sSpecialChars)
            sInput = Replace$(sInput, Mid$(sSpecialChars, i, 1), "")    'this will remove spaces
        Next
        removeSpecial = sInput
    
    End Function

    2) Amend your code to use that function, as well as select the first 30 character, or 29, whatever you want:
        Sheets(Sheets.Count).Name = Left(removeSpecial(projectCell.Value), 30) ' Renames the worksheets from the index of project.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-18-2015
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    20

    Re: Error handling when creating sheets based on list and hyperlink

    Thanks it works like a charm.

    Can anyone help me with the second part:
    2) I would also like to create an index in another column of the master sheet with the names and hyperlink of the newly created sheets.

    Thanks a lot

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Error handling when creating sheets based on list and hyperlink

    CREATE A HYPERLINKED LIST OF SHEETS IN A WORKBOOK ON A FRONT SHEET
    This macro creates a "table of contents" on a sheet at the beginning of the workbook. Each sheet listed is also an active Hyperlink so click the name will take you directly to the sheet. It demonstrates how to also collect some key pieces of data from each sheet to add to the LIST sheet to be more informative. It puts a link on all your original sheets in cell A1 back to this new LIST sheet and you have an extremely fast navigation system for large workbooks. There's a sample file for you to see this operate.
    Once the hyperlinks are created for you, you could reorganize them on that front sheet in any visual way you wish to make them easy to see all at once.
    Last edited by JBeaucaire; 12-26-2019 at 04:06 PM.

  5. #5
    Registered User
    Join Date
    08-18-2015
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    20

    Re: Error handling when creating sheets based on list and hyperlink

    Thanks. It solves partially my issue as what I wanted to achieve is having the hyperlink created in a column next to the projectCell column and only for the newly created tabs.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Error handling when creating sheets based on list and hyperlink

    The macro demonstrates all the techniques for creating a hyperlink and putting it in a cell. When you adapt those techniques into your specific goal/target then you will have knowingly absorbed this content and made it your own.

  7. #7
    Registered User
    Join Date
    08-18-2015
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    20

    Re: Error handling when creating sheets based on list and hyperlink

    Thanks, I manage to sort it out thanks to the concept

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating separate sheets based on single rows in list?
    By Taxster in forum Excel General
    Replies: 3
    Last Post: 12-16-2014, 04:24 PM
  2. [SOLVED] Error Handling: Creating code to display error messages
    By Student1990 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-01-2013, 02:21 PM
  3. Error Handling on Copy Sheets
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2011, 01:26 PM
  4. error handling - sheets.activate
    By inspector-71 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-04-2010, 08:33 AM
  5. Error handling with hyperlink looping
    By barksmith in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2009, 12:32 PM
  6. error handling when creating a file
    By mwc0914 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2006, 03:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1