Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Help on Run-time error after "Save As"

Hello,

I have an excel document with 6 sheets. Sheet2 has a Combo Box control which
I use to sort the data. I have the code in the Sheet2 code module.

Everything works great until I do a "Save As", then I sometimes get a
"Run-time error '1004': Sort Method of Range Class Failed" or for some
reason the Sheet5 becomes Active. I have no idea why this is happening.
Please Help!!

Here is the code for the Combo Box

Private Sub cmbSort_Change()

Sort_Data ActiveSheet, "1234", cmbSort.Value

End Sub

Private Sub Sort_Data(sht As Worksheet, pwd As String, val As String)

' Unprotect Worksheet
sht.Unprotect Password:=pwd

With Worksheets("PatientList")
If val = "Patient Name" Then
' Sort by Status by Patient Name
.Range("PatientData").Sort Key1:=.Range("Status"), _
Order1:=xlAscending, Key2:=.Range("Patient_Name"), _
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom

ElseIf val = "Patient Name (No Status)" Then
' Sort by Patient Name (No Status)
.Range("PatientData").Sort Key1:=.Range("Patient_Name"), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom

Else
' Sort by Assigned Counselor Initials (No Status)
.Range("PatientData").Sort Key1:=.Range("Couns_Assigned"), _
Order1:=xlAscending, Key2:=.Range("Patient_Name"), _
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End If
End With 'Worksheets("PatientList")

With sht
.Activate 'just to be SURE it is active
.Range("B9").Select

' Protect Worksheet
.Protect Password:=pwd, Scenarios:=True
End With
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting "Save As" adds "Copy of" to file name- MS Excel 2007 ronhansen Excel Discussion (Misc queries) 1 November 15th 09 09:33 PM
"CELL("FILENAME") NOT UPDATE AFTER "SAVE AS" ACTION yossie6 Excel Discussion (Misc queries) 1 June 16th 08 12:16 PM
ERROR: "Unable to save data and formatting" Gizmo63 Excel Discussion (Misc queries) 0 April 30th 07 12:20 PM
"Save" and "Save As" options greyed out - "Save as Webpage" option Bill Excel Discussion (Misc queries) 0 January 16th 07 04:47 PM
"Can't Show Modally" - Run-Time Error '400' Problem Bruce B[_2_] Excel Programming 3 July 14th 03 02:01 PM


All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"