Assigning a time value to a Worksheet name

ExcelRaceRatings

New Member
Joined
Jan 9, 2016
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a workbook with around 50 different worksheets. In cell C2 on each worksheet there is a time (eg - 10.41am). A two ended question:

1) Is there a way to assign the tab name to read the time value of C2?
2) If question one is possible then is there way to sort the sheets by time?

Thank you.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello,

Whit this code your sheets's are going to sort.

VBA Code:
Sub Sort_Active_Book()
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult

   iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
     & "Clicking No will sort in Descending Order", _
     vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
   For i = 1 To Sheets.Count
      For j = 1 To Sheets.Count - 1

         If iAnswer = vbYes Then
            If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
               Sheets(j).Move After:=Sheets(j + 1)
            End If

         ElseIf iAnswer = vbNo Then
            If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then
               Sheets(j).Move After:=Sheets(j + 1)
            End If
         End If
      Next j
   Next i
End Sub

This code will make the name of sheet = to cell "C2" value

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("C2")) Is Nothing Then
        ActiveSheet.Name = ActiveSheet.Range("C2")
    End If
End Sub
 
Upvote 0
Hi. Try:
VBA Code:
Sub NameAndSortSheets()
 Dim ws As Worksheet, n As Long, i As Long, j As Long
  For Each ws In ThisWorkbook.Sheets
   ws.Name = ws.[C2]
  Next ws
  n = ThisWorkbook.Sheets.Count
  For i = 1 To n - 1
   For j = i + 1 To n
    If Left(Sheets(j).Name, InStr(Sheets(j).Name, ".") - 1) * 1 < Left(Sheets(i).Name, InStr(Sheets(i).Name, ".") - 1) * 1 _
     Or Sheets(j).Name < Sheets(i).Name Then Sheets(j).Move Before:=Sheets(i)
   Next j
  Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top