Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Form Button vs Command Button

Excel 2003

I have a Form button with the following code in a Module. I want to use a
Command button so I can change the color of the button. When I run the same
code in the command button in the worksheet module I get a "Select method of
Range Class failed" error.

What's wrong?

Private Sub CommandButton10_Click()

ActiveWorkbook.Unprotect Password:="scott"
Sheets("Records").Visible = True
Sheets("AddRecords").Visible = False
Sheets("Records").Activate
Sheets("Records").Unprotect Password:="scott"
Range("B:B,E:G,I:N,P:W").Select
Range("W1").Activate
Selection.EntireColumn.Hidden = True
Range("C5").Select
ActiveSheet.EnableAutoFilter = True
ActiveSheet.Protect contents:=True, userInterfaceOnly:=True 'Added
Descend code here
Range("A4:W505").Sort Key1:=Range("A4"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("Records").Protect Password:="scott"
ActiveWorkbook.Protect Password:="scott"
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Form Button vs Command Button

Code in a standard module defaults to the active sheet. Code in a sheet
default to the sheet that it is in regardless of which sheet is active.

Private Sub CommandButton10_Click()

ThisWorkbook.Unprotect Password:="scott"
Sheets("AddRecords").Visible = False
with Sheets("Records")
.Visible = True
.Activate
.Unprotect Password:="scott"
.Range("B:B,E:G,I:N,P:W").EntireColumn.Hidden = True
.Range("C5").Select
.EnableAutoFilter = True
.Protect contents:=True, userInterfaceOnly:=True 'Added
'Descend code here
.Range("A4:W505").Sort Key1:=.Range("A4"), Order1:=xlDescending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
.Protect Password:="scott"
end with
ThisWorkbook.Protect Password:="scott"
End Sub
--
HTH...

Jim Thomlinson


"Gizmo" wrote:

Excel 2003

I have a Form button with the following code in a Module. I want to use a
Command button so I can change the color of the button. When I run the same
code in the command button in the worksheet module I get a "Select method of
Range Class failed" error.

What's wrong?

Private Sub CommandButton10_Click()

ActiveWorkbook.Unprotect Password:="scott"
Sheets("Records").Visible = True
Sheets("AddRecords").Visible = False
Sheets("Records").Activate
Sheets("Records").Unprotect Password:="scott"
Range("B:B,E:G,I:N,P:W").Select
Range("W1").Activate
Selection.EntireColumn.Hidden = True
Range("C5").Select
ActiveSheet.EnableAutoFilter = True
ActiveSheet.Protect contents:=True, userInterfaceOnly:=True 'Added
Descend code here
Range("A4:W505").Sort Key1:=Range("A4"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("Records").Protect Password:="scott"
ActiveWorkbook.Protect Password:="scott"
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Form Button vs Command Button

That did it. Thanks Jim

"Jim Thomlinson" wrote:

Code in a standard module defaults to the active sheet. Code in a sheet
default to the sheet that it is in regardless of which sheet is active.

Private Sub CommandButton10_Click()

ThisWorkbook.Unprotect Password:="scott"
Sheets("AddRecords").Visible = False
with Sheets("Records")
.Visible = True
.Activate
.Unprotect Password:="scott"
.Range("B:B,E:G,I:N,P:W").EntireColumn.Hidden = True
.Range("C5").Select
.EnableAutoFilter = True
.Protect contents:=True, userInterfaceOnly:=True 'Added
'Descend code here
.Range("A4:W505").Sort Key1:=.Range("A4"), Order1:=xlDescending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
.Protect Password:="scott"
end with
ThisWorkbook.Protect Password:="scott"
End Sub
--
HTH...

Jim Thomlinson


"Gizmo" wrote:

Excel 2003

I have a Form button with the following code in a Module. I want to use a
Command button so I can change the color of the button. When I run the same
code in the command button in the worksheet module I get a "Select method of
Range Class failed" error.

What's wrong?

Private Sub CommandButton10_Click()

ActiveWorkbook.Unprotect Password:="scott"
Sheets("Records").Visible = True
Sheets("AddRecords").Visible = False
Sheets("Records").Activate
Sheets("Records").Unprotect Password:="scott"
Range("B:B,E:G,I:N,P:W").Select
Range("W1").Activate
Selection.EntireColumn.Hidden = True
Range("C5").Select
ActiveSheet.EnableAutoFilter = True
ActiveSheet.Protect contents:=True, userInterfaceOnly:=True 'Added
Descend code here
Range("A4:W505").Sort Key1:=Range("A4"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("Records").Protect Password:="scott"
ActiveWorkbook.Protect Password:="scott"
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
macro attached to command button - VBA form Roy Gudgeon[_2_] Excel Discussion (Misc queries) 2 March 16th 10 12:44 PM
User form and Command button Marilyn Excel Discussion (Misc queries) 3 May 9th 07 12:50 AM
Form Command Button Problem.. Don Excel Programming 3 July 8th 06 02:17 AM
Command Button vs Form Button Bri[_3_] Excel Programming 2 February 3rd 06 08:18 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 08:06 PM.

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"