![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 38
|
how can i alter this formula so that it shows the Top number of players that the user types into the input box
Thankz in advance Sub Filter_Ltable() ' ' Filter_Ltable Macro ' Macro recorded 10/05/2002 by ' ' Dim x As Integer x = Application.InputBox("How many of the top players do you want to show" _ , "Enter number of players", 10, , , 1) Range("B4:H4").Select Selection.AutoFilter Selection.AutoFilter Field:=7, Criteria1:="10", Operator:=xlTop10Items Range("B5").Select End Sub |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Change:
Selection.AutoFilter Field:=7, Criteria1:="10", Operator:=xlTop10Items To: Selection.AutoFilter Field:=7, Criteria1:=x, Operator:=xlTop10Items Tom |
|
|
|
|
|
#3 |
|
New Member
Join Date: Apr 2002
Posts: 38
|
Tom, your formula only works if the user enters 10 into input box. I need it to work for any number
[ This Message was edited by: MERKY on 2002-05-09 17:53 ] |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
I don't know what your list is. I don't know why it is not working??? Did you change the criteria to x? Criteria1:=x Tom |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
it works alright on mine too
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
try it like this
Sub Filter_Ltable() Dim x x = (CLng(Application.InputBox("How many of the top players do you want to show" _ , "Enter number of players"))) range("b4":"h4").select If Selection.AutoFilterMode = False Then Selection.AutoFilterMode Selection.AutoFilter Field:=7, Criteria1:=(x), Operator:=xlTop10Items Range("B5").Select End Sub |
|
|
|
|
|
#7 | |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Quote:
Please let me know the advantage to use (). |
|
|
|
|
|
|
#8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Both of TsTom's code and brettvba's code are works on mine.
Assuming your sheet is like above image. brettvba, I always do not use () but my code is works fine too.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|