+ Reply to Thread
Results 1 to 9 of 9

Sheet name from cell values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Sheet name from cell values

    I have a code that takes date from "A7" and text from "G7" to name sheet. Sometimes however sheet names can be too long. How do I modify below code to get date and only the first letter of each word to form sheet name? So if "A7" is 9/24/23 and "G7" is "Georgia Network Meeting", then sheet name should be "Sep23-GNM".

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A7")) Is Nothing Then
    
        If Range("A7") = Empty Then
            ActiveSheet.Name = "Event" & ActiveSheet.Index - 1
        Else
            ActiveSheet.Name = Format(Range("A7").Value, ("mmmd")) & "-" & Range("G7")
            End If
    End If

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Sheet name from cell values

    Something like this will work

    Sub abc()
     MsgBox Format(Range("a7").Value, ("mmmd")) & "-" & FirstLetters(Range("g7").Value)
    End Sub
    Function FirstLetters(str As String)
        Dim words As Variant
        Dim resultStr As String
        Dim i As Integer
    
        words = Split(str)
        For i = 0 To UBound(words)
            resultStr = resultStr & Left(words(i), 1)
        Next i
    
        FirstLetters = UCase(resultStr)
    End Function
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Re: Sheet name from cell values

    The message box output is perfect but how can it be modified to change sheet name as in my original code?

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,864

    Re: Sheet name from cell values

    Private Sub Worksheet_Change(ByVal Target As Range)
     If Not Intersect(Target, Range("A7")) Is Nothing Then
    
        If Range("A7") = Empty Then
            ActiveSheet.Name = "Event" & ActiveSheet.Index - 1
        Else
            ActiveSheet.Name = Format(Range("A7").Value, ("mmmd")) & "-" & FirstLetters(Range("g7").Value)
            End If
    End If
    End Sub
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  5. #5
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Re: Sheet name from cell values

    I ran into Compile error: Sub or Function not defined highlighted on "FirstLetters".............

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,037

    Re: Sheet name from cell values

    You probably need to keep the Function FirstLetters from post #2

  7. #7
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Re: Sheet name from cell values

    I am a novice to VBA. Can you please put both those together to show me how it works? I continue to get Compile errors!

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,864

    Re: Sheet name from cell values

    See attached

    FUNCTION code is in Module1
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    03-12-2022
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    109

    Re: Sheet name from cell values

    YES! Thank you!

+ 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. [SOLVED] Sum cell values into another sheet IF values in cells from two sheets match
    By RaDoubleD in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-26-2018, 09:41 PM
  2. [SOLVED] Lookup values from sheet 2 with sheet 1 and copy found values in cell b of sheet 1
    By spa3212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-21-2016, 03:28 AM
  3. [SOLVED] VBA Help needed to create sheet based on master sheet column cell values
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-12-2016, 04:58 PM
  4. Replies: 3
    Last Post: 09-08-2014, 04:29 PM
  5. Replies: 5
    Last Post: 02-21-2013, 07:17 PM
  6. search cell values based on list of values in other sheet and add color to row
    By darkbraids in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2012, 08:35 AM
  7. Replies: 2
    Last Post: 06-04-2012, 06:57 AM

Tags for this Thread

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