Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Reversing a filter using a checkbox

Hi

I have this code working perfectly, which takes a variable (strToFind),
searches an array (Import_Data), and outputs all the matching records. easy.
There is also a function for reporting all values AllProjects_Report().

However, I want to include a checkbox labelled 'Exclude', which, if
selected, excludes these records from AllProjects_Report (effectively
producing a NOT report).

Apples $1.50 Roger
Apples $2.00 Ron
Peach $1.75 Steve
Banana $4.00 John

At the moment, selecting Apples as your criteria would produce:

Apples $1.50 Roger
Apples $2.00 Ron

But if the box is checked, i'd like it to produce;

Peach $1.75 Steve
Banana $4.00 John

logically:

If Exclude_Box = True, AllProjects_Report - Custom_Report

Below is the code for running a report, which is where I think I need to
alter.

__________________________________________________ _______________

Sub Run_Report()
' Run_Report Macro recorded 20/02/2007 by (me)
' This macro is the reporting engine
' It is called by each macro after the report criteria is set

Dim intS As Integer
Dim rngY As Range
Dim wSht As Worksheet
intS = 1

'Clear any existing report information
Worksheets("Report").Range("A:Z").Clear

Application.ScreenUpdating = True
Worksheets("Imported Data").Visible = True
Worksheets("Imported Data").Activate

Set wSht = Worksheets("Report")

With Selection
Set rngY = .Find(what:=strToFind, LookAt:=xlPart)
If Not rngY Is Nothing Then
FirstAddress = rngY.Address
Do
rngY.EntireRow.Copy wSht.Cells(intS, 1)
intS = intS + 1
Set rngY = .FindNext(rngY)
Loop While Not rngY Is Nothing And rngY.Address <
FirstAddress
End If
End With

' Run the report formatting engine
Worksheets("Imported Data").Visible = False
Application.Run "Report Generator v2.xls'!Report_Format"

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Reversing a filter using a checkbox

Sub Run_Report()
' Run_Report Macro recorded 20/02/2007 by (me)
' This macro is the reporting engine
' It is called by each macro after the report criteria is set
Dim FirstAddress As String
Dim intS As Integer
Dim rngY As Range
Dim wSht As Worksheet
Dim nDirection As Long
Dim StartCell As Range
Dim cbDrive As CheckBox

Application.ScreenUpdating = True
Set wSht = Worksheets("Report")
'Clear any existing report information
wSht.Range("A:Z").Clear
With Worksheets("Imported Data")
.Visible = True
.Activate
End With

With Selection
Set cbDrive = wSht.CheckBoxes("Check Box 1")
intS = 1
If cbDrive.Value = 1 Then
Set StartCell = Selection(Selection.Count)
.Copy wSht.Range("A1")
nDirection = xlPrevious
Else
Set StartCell = .Cells(1, 1)
nDirection = xlNext
End If
Set rngY = .Find(What:=strToFind, _
After:=StartCell, _
LookAt:=xlPart, _
SearchDirection:=nDirection)
If Not rngY Is Nothing Then
FirstAddress = rngY.Address
Do
If cbDrive.Value = 1 Then
wSht.Rows(rngY.Row).Delete
Else
rngY.EntireRow.Copy wSht.Cells(intS, 1)
End If
intS = intS + 1
Set rngY = .FindNext(rngY)
Loop While Not rngY Is Nothing And rngY.Address < FirstAddress
End If
End With

' Run the report formatting engine
Worksheets("Imported Data").Visible = False
Application.Run "Report Generator v2.xls'!Report_Format"

End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"D Zandveld" wrote in message
...
Hi

I have this code working perfectly, which takes a variable (strToFind),
searches an array (Import_Data), and outputs all the matching records.
easy.
There is also a function for reporting all values AllProjects_Report().

However, I want to include a checkbox labelled 'Exclude', which, if
selected, excludes these records from AllProjects_Report (effectively
producing a NOT report).

Apples $1.50 Roger
Apples $2.00 Ron
Peach $1.75 Steve
Banana $4.00 John

At the moment, selecting Apples as your criteria would produce:

Apples $1.50 Roger
Apples $2.00 Ron

But if the box is checked, i'd like it to produce;

Peach $1.75 Steve
Banana $4.00 John

logically:

If Exclude_Box = True, AllProjects_Report - Custom_Report

Below is the code for running a report, which is where I think I need to
alter.

__________________________________________________ _______________

Sub Run_Report()
' Run_Report Macro recorded 20/02/2007 by (me)
' This macro is the reporting engine
' It is called by each macro after the report criteria is set

Dim intS As Integer
Dim rngY As Range
Dim wSht As Worksheet
intS = 1

'Clear any existing report information
Worksheets("Report").Range("A:Z").Clear

Application.ScreenUpdating = True
Worksheets("Imported Data").Visible = True
Worksheets("Imported Data").Activate

Set wSht = Worksheets("Report")

With Selection
Set rngY = .Find(what:=strToFind, LookAt:=xlPart)
If Not rngY Is Nothing Then
FirstAddress = rngY.Address
Do
rngY.EntireRow.Copy wSht.Cells(intS, 1)
intS = intS + 1
Set rngY = .FindNext(rngY)
Loop While Not rngY Is Nothing And rngY.Address <
FirstAddress
End If
End With

' Run the report formatting engine
Worksheets("Imported Data").Visible = False
Application.Run "Report Generator v2.xls'!Report_Format"

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Reversing a filter using a checkbox

Might want to look at the Advanced filter under filters under the Data menu.

It should do all this without all the huffing and puffing. Just set up the
criteria you want, including exluding records.

for example to exclude apples
Dummy
=A4<"Apples"
goes in the criteria range. A4 refers to the first row of data (in your
example it is the containing Applels and Roger.

If I just wanted apples it would be

Fruit
Apples

(fruit would be the column header for your data

This can all be done with a couple lines of code.

--
Regards,
Tom Ogilvy


"D Zandveld" wrote:

Hi

I have this code working perfectly, which takes a variable (strToFind),
searches an array (Import_Data), and outputs all the matching records. easy.
There is also a function for reporting all values AllProjects_Report().

However, I want to include a checkbox labelled 'Exclude', which, if
selected, excludes these records from AllProjects_Report (effectively
producing a NOT report).

Apples $1.50 Roger
Apples $2.00 Ron
Peach $1.75 Steve
Banana $4.00 John

At the moment, selecting Apples as your criteria would produce:

Apples $1.50 Roger
Apples $2.00 Ron

But if the box is checked, i'd like it to produce;

Peach $1.75 Steve
Banana $4.00 John

logically:

If Exclude_Box = True, AllProjects_Report - Custom_Report

Below is the code for running a report, which is where I think I need to
alter.

__________________________________________________ _______________

Sub Run_Report()
' Run_Report Macro recorded 20/02/2007 by (me)
' This macro is the reporting engine
' It is called by each macro after the report criteria is set

Dim intS As Integer
Dim rngY As Range
Dim wSht As Worksheet
intS = 1

'Clear any existing report information
Worksheets("Report").Range("A:Z").Clear

Application.ScreenUpdating = True
Worksheets("Imported Data").Visible = True
Worksheets("Imported Data").Activate

Set wSht = Worksheets("Report")

With Selection
Set rngY = .Find(what:=strToFind, LookAt:=xlPart)
If Not rngY Is Nothing Then
FirstAddress = rngY.Address
Do
rngY.EntireRow.Copy wSht.Cells(intS, 1)
intS = intS + 1
Set rngY = .FindNext(rngY)
Loop While Not rngY Is Nothing And rngY.Address <
FirstAddress
End If
End With

' Run the report formatting engine
Worksheets("Imported Data").Visible = False
Application.Run "Report Generator v2.xls'!Report_Format"

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
How to have Checkbox A uncheck with checked Checkbox B Texas Aggie Excel Discussion (Misc queries) 3 July 20th 07 10:58 PM
link a checkbox in a sheet to a checkbox on a userform? Arjan Excel Programming 0 November 10th 06 01:37 PM
How do I link one checkbox to update another checkbox? Mike Excel Programming 3 April 28th 06 02:22 AM
checkbox on form reset from checkbox on sheet raw[_12_] Excel Programming 1 December 3rd 05 05:08 AM
Can you filter on an ActiveX checkbox in Excel Liz Excel Discussion (Misc queries) 1 August 13th 05 12:29 AM


All times are GMT +1. The time now is 02:20 AM.

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"