Friday, August 14, 2009

Sorting the sheets in an Excel file using VB of QTP?

Sub Sort_Sheets()


Dim Sort_Mode_Descending As Boolean
Dim No_of_Sheets As Integer
Dim Outer_Loop As Integer
Dim Inner_Loop As Integer
No_of_Sheets = Sheets.Count
'Change Flag As appropriate
Sort_Mode_Descending = False
For Outer_Loop = 1 To No_of_Sheets
For Inner_Loop = 1 To Outer_Loop
If Sort_Mode_Descending = True Then
If UCase(Sheets(Outer_Loop).Name) > UCase(Sheets(Inner_Loop).Name) Then
Sheets(Outer_Loop).Move Before:=Sheets(Inner_Loop)
End If
End If
If Sort_Mode_Descending = False Then
If UCase(Sheets(Outer_Loop).Name) < UCase(Sheets(Inner_Loop).Name) Then
Sheets(Outer_Loop).Move Before:=Sheets(Inner_Loop)
End If
End If

Next Inner_Loop
Next Outer_Loop


End Sub

Moving to a particular cell in the sheet:
Application.Goto ActiveSheet.Range("A54")

1 comment:


  1. You should be applauded for providing the articles and making the effort to provide the useful information you do. Keep up the great work & happy blogging!

    Zea
    www.imarksweb.org

    ReplyDelete