Вы находитесь на странице: 1из 10

This workbook (the other sheets) exemplify how you can hide columns and rows

with VBA macros using diffent criterias. If you press ALT+F11 you can inspect the
code in Excel's VBA editor.

The sheets Automatic1 and Automatic2 exemplify how code can be executed
automaticelly by putting code into the sheets' code sheets under "Microsoft Excel
Objects". If you cannot see the code sheets in the editor, press CTRL+R to open
Project Explorer.

The sheets' codesheets have som standard procedures that are called automatically
when certain events happen. We use the procedure Worksheet_Change.
On the sheets Find-Hide and Hide-empty-columns are some buttons (control elements),
and their code is on the code sheets too.

The examples

In Automatic1 a row is hidden, if you insert an "x" in column A. If you insert a 0 (zero)
instead, all hidden rows will become visible again, and all text in column A is deleted.

Automatic2 shows how you can hide rows using criteria. All rows (except row 1) will
be hidden, if they have the same value in column A as the value you put in cell A1.
If you insert a zero or press Delete in cell 1, all hidden rows will become visible again.

Find-Hide uses the search function. The user is prompted for a search string, and all
rows with this value in column B will be hidden. Here you must click a button.

Hide-empty-columns hides all empty columns in the range column 1-26. You can
easily modify this. Press a button to run the macro.
Eksempel p hvordan rkker kan skjules automatisk. Hertil bruges
fanebladets kodeblad og proceduren Worksheet_Change, som
kaldes automatisk, nr der ndres noget.

I dette eksempel skjules en rkke, hvis der indsttes et "x" i


kolonne A. Hvis der indstte et 0 (nul) vises alle skjulte rkker, og
indtastninger i kolonne A slettes.
utomatisk. Hertil bruges
heet_Change, som

indsttes et "x" i
s alle skjulte rkker, og
f

1 Example on how to automatically hide rows using a criteria. The example will
1 hide all rows that have the same value in colun A as in cell A1.
s
If for instance you insert "ww" in cell A1, all rows with "ww" in column A will be
hidden. If you insert a 0 (zero) or press Delete in cell A1, all hissen rows will
f
be visible again.
h The whole thing is controlled by the procedure Worksheet_Change in this
1 sheet's code sheet. It executes automatically if something is changed, and (in
ww this example) calls the macro "HideUsingCriteria" in Module1.
1
y

2
0
using a criteria. The example will
lun A as in cell A1.

ows with "ww" in column A will be


te in cell A1, all hissen rows will

ure Worksheet_Change in this


y if something is changed, and (in
teria" in Module1.
777 The button "Search and find in
Search and find in column B "FindGide".

Clicking the button "Show all hid


777

777
Show all hidden
Not 777

777
777
777

Ducksville

Ducksville

777
The button "Search and find in column B" will run the macro
"FindGide".

Clicking the button "Show all hidden" will unhide any hidden rows.
The button "Hide empty columns" runs the macro
"HideEmptyColumns" that hides all empty columns in column 1 -
26.

"Show all hidden" will unhide hidden columns.

a b c d e

Hide empty columns

Show all hidden


macro
olumns in column 1 -

s.

f g h i j
k l m n

Вам также может понравиться