Consulting

Results 1 to 2 of 2

Thread: sort worksheets not case sensitive

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    sort worksheets not case sensitive

    hello all
    the following macro sort worksheets in a wb by name.
    it is case sensitive.namely a sheets beginning with A comes before a.
    i want the code to rank sheet by name regardless of case.
    [VBA]
    Sub SortWorksheets()
    Dim sCount As Integer, i As Integer, j As Integer
    Application.ScreenUpdating = False
    sCount = Worksheets.Count
    If sCount = 1 Then Exit Sub
    For i = 1 To sCount - 1
    For j = i + 1 To sCount
    If Worksheets(j).Name < Worksheets(i).Name Then
    Worksheets(j).Move Before:=Worksheets(i)
    End If
    Next j
    Next i
    End Sub

    [/VBA]
    thanks
    moshe

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Moshe
    Add "Option Compare Text" before your code.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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