Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Filter Month then name

Hi there I have this following code at the moment,

Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

If cnt 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub

It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.

But I am having all sorts of trouble getting it to work.

Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Filter Month then name

As previously answered:

cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")

determines which column to look for the range. If cnt is zero, it doesn't
find that name for that month in the second column and therefore looks for
it in the third column. Put in a message box to display the Cnt. then see
if you agree with the count.

Your original description said to filter on one set of names and if not
found there, then filter on the second set of names instead. If you want to
display a row if it is in either or show relevant risks, then the easiest
would be to have the code add a formula in the next available column that
would indicate whether to display that row or not and simply autofilter on
that formula.

=IF(AND(OR(C2="John",D2="John"),B2="June"),"Show", IF((TRUE),"Relevant","no
show"))

True represents some formula that determines if the row is risk relevant.

so it would be something like:

rng.offset(0,10).Formula = "=if(And(Or(C2=""" & Combobox2.value & _
""",D2=""" & Combobox2.value & """)" & _
",B2=""" & Combobox1.Value & """),""Show"",if((True),""Relevant"",""no
show""))"



--
Regards,
Tom Ogilvy



"Pasty" wrote:

Hi there I have this following code at the moment,

Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

If cnt 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub

It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.

But I am having all sorts of trouble getting it to work.

Regards

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Filter Month then name

Hi Tom,

I've tried this but it doesn't appear to be working so I assume its me
putting it in the wrong place.


"Tom Ogilvy" wrote:

As previously answered:

cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")

determines which column to look for the range. If cnt is zero, it doesn't
find that name for that month in the second column and therefore looks for
it in the third column. Put in a message box to display the Cnt. then see
if you agree with the count.

Your original description said to filter on one set of names and if not
found there, then filter on the second set of names instead. If you want to
display a row if it is in either or show relevant risks, then the easiest
would be to have the code add a formula in the next available column that
would indicate whether to display that row or not and simply autofilter on
that formula.

=IF(AND(OR(C2="John",D2="John"),B2="June"),"Show", IF((TRUE),"Relevant","no
show"))

True represents some formula that determines if the row is risk relevant.

so it would be something like:

rng.offset(0,10).Formula = "=if(And(Or(C2=""" & Combobox2.value & _
""",D2=""" & Combobox2.value & """)" & _
",B2=""" & Combobox1.Value & """),""Show"",if((True),""Relevant"",""no
show""))"



--
Regards,
Tom Ogilvy



"Pasty" wrote:

Hi there I have this following code at the moment,

Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

If cnt 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub

It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.

But I am having all sorts of trouble getting it to work.

Regards

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Filter Month then name

It would be hard to tell.

--
Regards,
Tom Ogilvy


"Pasty" wrote:

Hi Tom,

I've tried this but it doesn't appear to be working so I assume its me
putting it in the wrong place.


"Tom Ogilvy" wrote:

As previously answered:

cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")

determines which column to look for the range. If cnt is zero, it doesn't
find that name for that month in the second column and therefore looks for
it in the third column. Put in a message box to display the Cnt. then see
if you agree with the count.

Your original description said to filter on one set of names and if not
found there, then filter on the second set of names instead. If you want to
display a row if it is in either or show relevant risks, then the easiest
would be to have the code add a formula in the next available column that
would indicate whether to display that row or not and simply autofilter on
that formula.

=IF(AND(OR(C2="John",D2="John"),B2="June"),"Show", IF((TRUE),"Relevant","no
show"))

True represents some formula that determines if the row is risk relevant.

so it would be something like:

rng.offset(0,10).Formula = "=if(And(Or(C2=""" & Combobox2.value & _
""",D2=""" & Combobox2.value & """)" & _
",B2=""" & Combobox1.Value & """),""Show"",if((True),""Relevant"",""no
show""))"



--
Regards,
Tom Ogilvy



"Pasty" wrote:

Hi there I have this following code at the moment,

Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

If cnt 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub

It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.

But I am having all sorts of trouble getting it to work.

Regards

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Filter Month then name

Its actually this bit that seems to be causing the problems

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

Saying its an error 1004 Application-defined or object-defined error

Which is odd as I have got it to work on other workbooks.

"Tom Ogilvy" wrote:

It would be hard to tell.

--
Regards,
Tom Ogilvy


"Pasty" wrote:

Hi Tom,

I've tried this but it doesn't appear to be working so I assume its me
putting it in the wrong place.


"Tom Ogilvy" wrote:

As previously answered:

cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")

determines which column to look for the range. If cnt is zero, it doesn't
find that name for that month in the second column and therefore looks for
it in the third column. Put in a message box to display the Cnt. then see
if you agree with the count.

Your original description said to filter on one set of names and if not
found there, then filter on the second set of names instead. If you want to
display a row if it is in either or show relevant risks, then the easiest
would be to have the code add a formula in the next available column that
would indicate whether to display that row or not and simply autofilter on
that formula.

=IF(AND(OR(C2="John",D2="John"),B2="June"),"Show", IF((TRUE),"Relevant","no
show"))

True represents some formula that determines if the row is risk relevant.

so it would be something like:

rng.offset(0,10).Formula = "=if(And(Or(C2=""" & Combobox2.value & _
""",D2=""" & Combobox2.value & """)" & _
",B2=""" & Combobox1.Value & """),""Show"",if((True),""Relevant"",""no
show""))"



--
Regards,
Tom Ogilvy



"Pasty" wrote:

Hi there I have this following code at the moment,

Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

If cnt 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub

It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.

But I am having all sorts of trouble getting it to work.

Regards



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Filter Month then name

If you want to send me a sample workbook, I will work it out for you.



--
Regards,
Tom Ogilvy


"Pasty" wrote:

Its actually this bit that seems to be causing the problems

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

Saying its an error 1004 Application-defined or object-defined error

Which is odd as I have got it to work on other workbooks.

"Tom Ogilvy" wrote:

It would be hard to tell.

--
Regards,
Tom Ogilvy


"Pasty" wrote:

Hi Tom,

I've tried this but it doesn't appear to be working so I assume its me
putting it in the wrong place.


"Tom Ogilvy" wrote:

As previously answered:

cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")

determines which column to look for the range. If cnt is zero, it doesn't
find that name for that month in the second column and therefore looks for
it in the third column. Put in a message box to display the Cnt. then see
if you agree with the count.

Your original description said to filter on one set of names and if not
found there, then filter on the second set of names instead. If you want to
display a row if it is in either or show relevant risks, then the easiest
would be to have the code add a formula in the next available column that
would indicate whether to display that row or not and simply autofilter on
that formula.

=IF(AND(OR(C2="John",D2="John"),B2="June"),"Show", IF((TRUE),"Relevant","no
show"))

True represents some formula that determines if the row is risk relevant.

so it would be something like:

rng.offset(0,10).Formula = "=if(And(Or(C2=""" & Combobox2.value & _
""",D2=""" & Combobox2.value & """)" & _
",B2=""" & Combobox1.Value & """),""Show"",if((True),""Relevant"",""no
show""))"



--
Regards,
Tom Ogilvy



"Pasty" wrote:

Hi there I have this following code at the moment,

Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

If cnt 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub

It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.

But I am having all sorts of trouble getting it to work.

Regards

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Filter Month then name

Where should I send it to?

"Pasty" wrote:

Hi there I have this following code at the moment,

Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")

rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value

If cnt 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub

It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.

But I am having all sorts of trouble getting it to work.

Regards

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
Filter out unique additions month to month Rookie_User Excel Discussion (Misc queries) 3 March 13th 09 02:29 PM
Filter by month, then day, not just day honyacker Excel Discussion (Misc queries) 1 March 21st 07 06:16 PM
Need to filter by month mikeybmdb Excel Discussion (Misc queries) 3 November 1st 05 01:53 PM
filter by month Duncan_J Excel Programming 2 April 1st 05 02:17 PM
Filter by month Marci Excel Discussion (Misc queries) 3 January 10th 05 05:53 AM


All times are GMT +1. The time now is 05:39 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"