LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Long-winded code

I have written 2 blocks of code to Initialise a User Form: the first defines
a range for a Worksheet Function (Max) and the second performs a test to
determine which of 9 buttons, should be visible. The User Form is named
TiedVote, and the Buttons B1 to B9.

My code works, but is long-winded. Can anyone suggest a method to achieve
the same functionality but simplify the repetitive code?

Private Sub UserForm_Initialize()

Select Case RoundN
Case 1
Set Voting = Worksheets("Rules").Range("K17:K25")
Case 2
Set Voting = Worksheets("Rules").Range("L17:L25")
Case 3
Set Voting = Worksheets("Rules").Range("M17:M25")
Case 4
Set Voting = Worksheets("Rules").Range("N17:N25")
Case 5
Set Voting = Worksheets("Rules").Range("O17:O25")
Case 6
Set Voting = Worksheets("Rules").Range("P17:P25")
Case 7
Set Voting = Worksheets("Rules").Range("Q17:Q25")
End Select*

If Sheets("Rules").Cells(17, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B1.Visible = True
Else
TiedVote.B1.Visible = False
End If
If Sheets("RULES").Cells(18, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B2.Visible = True
Else
TiedVote.B2.Visible = False
End If
If Sheets("RULES").Cells(19, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B3.Visible = True
Else
TiedVote.B3.Visible = False
End If
If Sheets("RULES").Cells(20, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
Else
TiedVote.B4.Visible = False
End If
If Sheets("RULES").Cells(21, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B5.Visible = True
Else
TiedVote.B5.Visible = False
End If
If Sheets("RULES").Cells(22, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B6.Visible = True
Else
TiedVote.B6.Visible = False
End If
If Sheets("RULES").Cells(23, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B7.Visible = True
Else
TiedVote.B7.Visible = False
End If
If Sheets("RULES").Cells(24, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B8.Visible = True
Else
TiedVote.B8.Visible = False
End If
If Sheets("RULES").Cells(25, 10 + RoundN).Value = _
Application.WorksheetFunction.Max(Voting) Then
TiedVote.B9.Visible = True
Else
TiedVote.B9.Visible = False
End If

End Sub


 
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
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Replace html code - formula too long andy62 Excel Discussion (Misc queries) 1 February 24th 09 09:48 PM
Code takes to long Oggy Excel Discussion (Misc queries) 1 March 30th 08 10:56 PM
Long Code Alam Excel Discussion (Misc queries) 2 November 15th 07 08:46 AM
my code too long? Zach Excel Worksheet Functions 2 August 3rd 05 07:53 PM


All times are GMT +1. The time now is 05:35 AM.

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

About Us

"It's about Microsoft Excel"