#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Filter

Hi,

I have set up a user form with two drop downs one for the persons name and
the other for the current month. What I want it to do is when they select
their name it will filter through Column C and just show the information
relating to them and if its not in this Column to then filter through Column
D (this is because there is a primary and secondary delegate in case of
abscence). With the month this looks at Column B as they have to look at
certain bits at certain times and i would also like this filtered. Here is an
example of how it looks.

Month Of
Review Primary person Secondary person
July Charles Stewart-Jenssen Richard Anderson

How can I achieve this?

Regards

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

Dim rng1 as Range, rng2 as Range
dim cell as Range, rng as Range
Dim bfound as Boolean

set rng = Range(cells(2,1),cells(rows.count,1).End(xlup))
for each cell in rng
if cell.Value = Combobox2.Value then
if cell.offset(0,1).Value = Combobox2.Value then
bfound = True
set rng1 = cell
exit for
end if
if cell.offset(0,2).Value = Combobox2.Value then
set rng2 = cell
end if
end if
Next
if not bFound then
if not rng2 is nothing then
set rng1 = rng2
else
MsgBox "Not found"
exit sub
end if
End if
Msgbox "Found at row: " & rng1.row

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Hi,

I have set up a user form with two drop downs one for the persons name and
the other for the current month. What I want it to do is when they select
their name it will filter through Column C and just show the information
relating to them and if its not in this Column to then filter through Column
D (this is because there is a primary and secondary delegate in case of
abscence). With the month this looks at Column B as they have to look at
certain bits at certain times and i would also like this filtered. Here is an
example of how it looks.

Month Of
Review Primary person Secondary person
July Charles Stewart-Jenssen Richard Anderson

How can I achieve this?

Regards

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

Where would this code go? I a module, userform or on the actual worksheet?

"Tom Ogilvy" wrote:

Dim rng1 as Range, rng2 as Range
dim cell as Range, rng as Range
Dim bfound as Boolean

set rng = Range(cells(2,1),cells(rows.count,1).End(xlup))
for each cell in rng
if cell.Value = Combobox2.Value then
if cell.offset(0,1).Value = Combobox2.Value then
bfound = True
set rng1 = cell
exit for
end if
if cell.offset(0,2).Value = Combobox2.Value then
set rng2 = cell
end if
end if
Next
if not bFound then
if not rng2 is nothing then
set rng1 = rng2
else
MsgBox "Not found"
exit sub
end if
End if
Msgbox "Found at row: " & rng1.row

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Hi,

I have set up a user form with two drop downs one for the persons name and
the other for the current month. What I want it to do is when they select
their name it will filter through Column C and just show the information
relating to them and if its not in this Column to then filter through Column
D (this is because there is a primary and secondary delegate in case of
abscence). With the month this looks at Column B as they have to look at
certain bits at certain times and i would also like this filtered. Here is an
example of how it looks.

Month Of
Review Primary person Secondary person
July Charles Stewart-Jenssen Richard Anderson

How can I achieve this?

Regards

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

After rereading you post, I had second thoughts.

This should be the click event for Combobox2 (Month name)

Private Sub Combobox2_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 & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")
rng.Resize(, 3).AutoFilter Field:=1, _
Criteria1:=ComboBox2.Value

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

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Where would this code go? I a module, userform or on the actual worksheet?

"Tom Ogilvy" wrote:

Dim rng1 as Range, rng2 as Range
dim cell as Range, rng as Range
Dim bfound as Boolean

set rng = Range(cells(2,1),cells(rows.count,1).End(xlup))
for each cell in rng
if cell.Value = Combobox2.Value then
if cell.offset(0,1).Value = Combobox2.Value then
bfound = True
set rng1 = cell
exit for
end if
if cell.offset(0,2).Value = Combobox2.Value then
set rng2 = cell
end if
end if
Next
if not bFound then
if not rng2 is nothing then
set rng1 = rng2
else
MsgBox "Not found"
exit sub
end if
End if
Msgbox "Found at row: " & rng1.row

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Hi,

I have set up a user form with two drop downs one for the persons name and
the other for the current month. What I want it to do is when they select
their name it will filter through Column C and just show the information
relating to them and if its not in this Column to then filter through Column
D (this is because there is a primary and secondary delegate in case of
abscence). With the month this looks at Column B as they have to look at
certain bits at certain times and i would also like this filtered. Here is an
example of how it looks.

Month Of
Review Primary person Secondary person
July Charles Stewart-Jenssen Richard Anderson

How can I achieve this?

Regards

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

Its a step in the right direction but it comes up with that end/debug error
and highlights this line

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

"Tom Ogilvy" wrote:

After rereading you post, I had second thoughts.

This should be the click event for Combobox2 (Month name)

Private Sub Combobox2_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 & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")
rng.Resize(, 3).AutoFilter Field:=1, _
Criteria1:=ComboBox2.Value

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

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Where would this code go? I a module, userform or on the actual worksheet?

"Tom Ogilvy" wrote:

Dim rng1 as Range, rng2 as Range
dim cell as Range, rng as Range
Dim bfound as Boolean

set rng = Range(cells(2,1),cells(rows.count,1).End(xlup))
for each cell in rng
if cell.Value = Combobox2.Value then
if cell.offset(0,1).Value = Combobox2.Value then
bfound = True
set rng1 = cell
exit for
end if
if cell.offset(0,2).Value = Combobox2.Value then
set rng2 = cell
end if
end if
Next
if not bFound then
if not rng2 is nothing then
set rng1 = rng2
else
MsgBox "Not found"
exit sub
end if
End if
Msgbox "Found at row: " & rng1.row

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Hi,

I have set up a user form with two drop downs one for the persons name and
the other for the current month. What I want it to do is when they select
their name it will filter through Column C and just show the information
relating to them and if its not in this Column to then filter through Column
D (this is because there is a primary and secondary delegate in case of
abscence). With the month this looks at Column B as they have to look at
certain bits at certain times and i would also like this filtered. Here is an
example of how it looks.

Month Of
Review Primary person Secondary person
July Charles Stewart-Jenssen Richard Anderson

How can I achieve this?

Regards



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Filter

Its a step in the right direction
Thats cute! <g

Must be you/your layout. the code was taken from a module where it
performed as designed. You will have to tweak it to your layout.
--
Regards,
Tom Ogilvy

"Pasty" wrote in message
...
Its a step in the right direction but it comes up with that end/debug
error
and highlights this line

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

"Tom Ogilvy" wrote:

After rereading you post, I had second thoughts.

This should be the click event for Combobox2 (Month name)

Private Sub Combobox2_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 & "=""" & _
ComboBox2.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & ComboBox1.Value & """))")
rng.Resize(, 3).AutoFilter Field:=1, _
Criteria1:=ComboBox2.Value

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

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Where would this code go? I a module, userform or on the actual
worksheet?

"Tom Ogilvy" wrote:

Dim rng1 as Range, rng2 as Range
dim cell as Range, rng as Range
Dim bfound as Boolean

set rng = Range(cells(2,1),cells(rows.count,1).End(xlup))
for each cell in rng
if cell.Value = Combobox2.Value then
if cell.offset(0,1).Value = Combobox2.Value then
bfound = True
set rng1 = cell
exit for
end if
if cell.offset(0,2).Value = Combobox2.Value then
set rng2 = cell
end if
end if
Next
if not bFound then
if not rng2 is nothing then
set rng1 = rng2
else
MsgBox "Not found"
exit sub
end if
End if
Msgbox "Found at row: " & rng1.row

--
Regards,
Tom Ogilvy

"Pasty" wrote:

Hi,

I have set up a user form with two drop downs one for the persons
name and
the other for the current month. What I want it to do is when they
select
their name it will filter through Column C and just show the
information
relating to them and if its not in this Column to then filter
through Column
D (this is because there is a primary and secondary delegate in
case of
abscence). With the month this looks at Column B as they have to
look at
certain bits at certain times and i would also like this filtered.
Here is an
example of how it looks.

Month Of
Review Primary person Secondary person
July Charles Stewart-Jenssen Richard Anderson

How can I achieve this?

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
DataFilterAuto Filter in excel 2007? TIJ New Users to Excel 2 November 13th 08 03:28 AM
Filter PivotTable dropdown items to match report filter Catherine D Excel Discussion (Misc queries) 1 August 16th 08 12:12 AM
filter: how to print filter list options in dropdown box help please Excel Discussion (Misc queries) 2 October 17th 07 01:53 AM
Need macro to filter, create tab on filter and copy/paste Jen[_11_] Excel Programming 1 May 2nd 06 04:45 PM
"Criteria Range" in the "Data/Filter/Advanced Filter" to select Du TC Excel Worksheet Functions 1 May 12th 05 02:06 AM


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