From: JuanManuel on
Hi,
I'm trying to implement something similar to AutoFilter in Excel. I have
several tables in a document. Two of the columns in each table are called
“Service Description” and “Type of inspection” respectively. Since there are
only three Types of inspection, a simplified version of those two columns
could look as follows:

“Service Description” “Type of Inspection”
Description1 C1
Description2 C1
Description3 HGP
Description4 HGP
Description5 MI
Description6 MI

Let's suppose that every table has something similar to what's shown above.
What I would like to accomplish is that through the click of a button or a
macrobutton field or whichever you consider is the most appropriate event
handler, every table in the document gets filtered based on the Type of
Inspection.

I was thinking about having three macrobutton fields, called "CI", "HGP" and
"MI", so that upon double-clicking "CI" for example, every table in the
document hides/unhides the appropriate rows. (i.e it only shows the rows that
correspond to a CI Inpection Type).

Is there a way to accomplish this? How can I refer to each table in a
document? and moreover, How can I select the appropriate range to hide it
based on the clicked button?

Thank you,

Juan
From: Jonathan West on
Word doesn't have hidden rows & columns the way Excel does. Therefore, you
can't hide/unhide rows. What you could do is delete unwanted rows.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

"JuanManuel" <JuanManuel(a)discussions.microsoft.com> wrote in message
news:EF95554A-51D1-49DB-8C15-EDB3994FCDBC(a)microsoft.com...
> Hi,
> I'm trying to implement something similar to AutoFilter in Excel. I have
> several tables in a document. Two of the columns in each table are called
> "Service Description" and "Type of inspection" respectively. Since there
> are
> only three Types of inspection, a simplified version of those two columns
> could look as follows:
>
> "Service Description" "Type of Inspection"
> Description1 C1
> Description2 C1
> Description3 HGP
> Description4 HGP
> Description5 MI
> Description6 MI
>
> Let's suppose that every table has something similar to what's shown
> above.
> What I would like to accomplish is that through the click of a button or a
> macrobutton field or whichever you consider is the most appropriate event
> handler, every table in the document gets filtered based on the Type of
> Inspection.
>
> I was thinking about having three macrobutton fields, called "CI", "HGP"
> and
> "MI", so that upon double-clicking "CI" for example, every table in the
> document hides/unhides the appropriate rows. (i.e it only shows the rows
> that
> correspond to a CI Inpection Type).
>
> Is there a way to accomplish this? How can I refer to each table in a
> document? and moreover, How can I select the appropriate range to hide it
> based on the clicked button?
>
> Thank you,
>
> Juan


From: Helmut Weber on
Hi Jonathan,

>Word doesn't have hidden rows & columns the way Excel does. Therefore, you
>can't hide/unhide rows. What you could do is delete unwanted rows.

hmm...

Sub Macro2()
With ActiveWindow.View
.ShowHiddenText = False
End With
ActiveDocument.Tables(1).Rows(2).Range.Font.Hidden = True
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
From: JuanManuel on
Hi Helmut,

I have no problem trying to hide rows, especially when I know exactly which
row I'm hiding or when I'm hiding the range going from any row to the end of
the table.

Nevertheless, my problem arises because the current tables can be edited at
any point in time and I'd like the code to keep working.

I'm trying to implement something similar to AutoFilter in Excel. The
document I'm working with has many tables with more than 5 columns. Two of
the
columns in each table are called “Service Description” and “Type of
inspection” respectively. Since there are only three Types of inspection, a
simplified version of those two columns could look as follows:

“Service Description” “Type of Inspection”
Description1 C1
Description2 C1
Description3 HGP
Description4 HGP
Description5 MI
Description6 MI

(The contents are only an example, they vary per table)

Let's suppose that every table has something similar to what's shown above.
Thanks to other mvp's, I ALREADY have macrobutton fields in certain rows of
each table that hide/unhide the remaining rows below it. (i.e., below the row
at which the macrobutton field is positioned).

What I would like to accomplish now is some sort of selective unhiding or
filtering. For example, let's suppose that I have three radiobuttons at the
very first page of the document called "CI", "HGP" and "MI" respectively.
Let's also suppose that at the time of clicking one of the hide/unhide
macrobutton fields, the "CI" radiobutton is selected.

Let's assume that the table has all of its rows hidden before the
macrobutton field is double-clicked. Once it gets, double-clicked and since
the "CI" radiobutton is the one selected, I'd like the table to show the
following:

“Service Description” “Type of Inspection”
Description1 C1
Description2 C1


I was thinking about having three radiobuttons, called "CI", "HGP" and
"MI", so that upon double-clicking "MI" for example, every table in the
document hides/unhides the appropriate rows. (i.e it only shows the rows that
correspond to a MI Inpection Type).

Is there a way to accomplish this?
I'm open to suggestions, can this be accomplished in a different way?

If this is an appropriate method,
How can I select the appropriate range to unhide it based on the selected
radiobutton?

I'm thinking about using the text in the "Type of inspection" column to find
the exact range that needs to be unhidden depending on the radiobutton
selected, but I don't know how. I have:

For i = 1 To TheTable.Rows.Count - StartRow
TextinCell = TheTable.Rows(StartRow + i).Cells(StartColumn +
1).Range.Text
If TextinCell = "C1" Then
TheTable.Rows(StartRow + i).range.font.hidden=false
Else:
TheTable.Rows(StartRow + i).range.font.hidden=false
End If
Next

This procedure locates the column "Type of Inspection" and goes through each
cell testing its text. It's supposed to unhide the appropriate rows depending
on the cell's text. Nevertheless, it doesn't work because of a funny little
square that it includes in each cell to the right of the text. I'm assuming
they are the same squares that appear when you press ctrl + shift + 8. How
can I get read of them??

Or is there a better way to accomplish this?

Thank you,

Juan


"Helmut Weber" wrote:

> Hi Jonathan,
>
> >Word doesn't have hidden rows & columns the way Excel does. Therefore, you
> >can't hide/unhide rows. What you could do is delete unwanted rows.
>
> hmm...
>
> Sub Macro2()
> With ActiveWindow.View
> .ShowHiddenText = False
> End With
> ActiveDocument.Tables(1).Rows(2).Range.Font.Hidden = True
> End Sub
>
> --
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP
>
From: Helmut Weber on
Hi Juan,

perhaps like that:

Sub Macro2()
Dim oTbl As Table
Dim lClm As Long ' columnindex
Dim sTmp As String ' text of cell
Dim oClm As Column ' a column
Dim oCll As Cell ' a cell
With ActiveWindow.View
.ShowHiddenText = False
End With
If Selection.Information(wdWithInTable) = False Then
MsgBox "Cursor not in table"
Exit Sub
End If
sTmp = Selection.Cells(1).Range.Text
lClm = Selection.Cells(1).ColumnIndex
For Each oTbl In ActiveDocument.Tables
For Each oCll In oTbl.Columns(lClm).Cells
If oCll.RowIndex > 1 Then
If oCll.Range.Text <> sTmp Then
oCll.Row.Range.Font.Hidden = _
Not oCll.Row.Range.Font.Hidden
End If
End If
Next
Next
End Sub

You got to place the cursor in the cell
with the text that serves as filter.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP