ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to hide rows/colums by value (https://www.excelbanter.com/excel-programming/372728-macro-hide-rows-colums-value.html)

[email protected]

Macro to hide rows/colums by value
 
HIDING
I'd like to be able to hide various rows and columns that have the
number 1 in their first position.

For example:

If A4 =1 then hide row 4.

If B6=1 then hide column B.

I'm okay with never being alble to hide row 1 or column A so there
shouldn't be any conflict/ambiguity.

UNHIDING
I'm happy to just unhide all when I need to unhide any. How can I do
that?

Would someone point me in the right direction?

Thanks for any help.

/e

Tom Ogilvy

Macro to hide rows/colums by value
 
why a row for A4 and a column for B6?

What are your rules,

What cells should be checked.

Is this something you would do by running a macro, or do you want them to
magically hide when you enter the 1 - or is the 1 produced by calculation.

Help yourself by providing a complete explanation of what you want to do.

sub RunMe()
With Range("A4")
.EntireRow.Hidden = ( .Value = 1)
end with
With Range("B6")
.entirecolumn.Hidden = (.Value = 1)
End With
End sub

--
Regards,
Tom Ogilvy






" wrote:

HIDING
I'd like to be able to hide various rows and columns that have the
number 1 in their first position.

For example:

If A4 =1 then hide row 4.

If B6=1 then hide column B.

I'm okay with never being alble to hide row 1 or column A so there
shouldn't be any conflict/ambiguity.

UNHIDING
I'm happy to just unhide all when I need to unhide any. How can I do
that?

Would someone point me in the right direction?

Thanks for any help.

/e


[email protected]

Macro to hide rows/colums by value
 
Tom,

A4 and B6 were examples.

I'd like to be able to define the rows rows and columns to hide by
manually placing a value of 1 in cells around the perimeter of the
sheet.

I do not need execution of the hide and unhide macros hooked to any
events; I'll run them manually.

That is:

Columns: For each column I want to hide, I'll place a 1 in row 1 at
the corresponding column.

Rows: For each row I want to hide, I'll place a 1 in column A on the
corresponding row.

But the question arises: Should we hide a row or a column if user
placed 1 in A1? So I originally said I'd be happy to ignore A1. But I
now see that a 1 in A1 should hide both row 1 AND column A. That'd be
perfect as I don't need to see those manually placed 1 values except
after an "unhide all" operation..

Is that fully clear?

Thanks.

/e





On Tue, 12 Sep 2006 09:37:03 -0700, Tom Ogilvy
wrote:

why a row for A4 and a column for B6?

What are your rules,

What cells should be checked.

Is this something you would do by running a macro, or do you want them to
magically hide when you enter the 1 - or is the 1 produced by calculation.

Help yourself by providing a complete explanation of what you want to do.

sub RunMe()
With Range("A4")
.EntireRow.Hidden = ( .Value = 1)
end with
With Range("B6")
.entirecolumn.Hidden = (.Value = 1)
End With
End sub


eliano[_2_]

Macro to hide rows/colums by value
 
Hi friends.
Try:

Sub RunMe()
With Range("A1")
..EntireRow.Hidden = (.Value = "a")
'End With
'With Range("A1")
..EntireColumn.Hidden = (.Value = "A")
End With
End Sub

Regards,
Eliano


ha scritto:

Tom,

A4 and B6 were examples.

I'd like to be able to define the rows rows and columns to hide by
manually placing a value of 1 in cells around the perimeter of the
sheet.

I do not need execution of the hide and unhide macros hooked to any
events; I'll run them manually.

That is:

Columns: For each column I want to hide, I'll place a 1 in row 1 at
the corresponding column.

Rows: For each row I want to hide, I'll place a 1 in column A on the
corresponding row.

But the question arises: Should we hide a row or a column if user
placed 1 in A1? So I originally said I'd be happy to ignore A1. But I
now see that a 1 in A1 should hide both row 1 AND column A. That'd be
perfect as I don't need to see those manually placed 1 values except
after an "unhide all" operation..

Is that fully clear?



eliano[_2_]

Macro to hide rows/colums by value
 
Sorry.:-)

Manually ?
..EntireRow.Hidden = (.Value = "R")
..EntireColumn.Hidden = (.Value = "C")

Eliano

eliano ha scritto:

Hi friends.
Try:

Sub RunMe()
With Range("A1")
.EntireRow.Hidden = (.Value = "a")
'End With
'With Range("A1")
.EntireColumn.Hidden = (.Value = "A")
End With
End Sub

Regards,
Eliano


ha scritto:

Tom,

A4 and B6 were examples.

I'd like to be able to define the rows rows and columns to hide by
manually placing a value of 1 in cells around the perimeter of the
sheet.

I do not need execution of the hide and unhide macros hooked to any
events; I'll run them manually.

That is:

Columns: For each column I want to hide, I'll place a 1 in row 1 at
the corresponding column.

Rows: For each row I want to hide, I'll place a 1 in column A on the
corresponding row.

But the question arises: Should we hide a row or a column if user
placed 1 in A1? So I originally said I'd be happy to ignore A1. But I
now see that a 1 in A1 should hide both row 1 AND column A. That'd be
perfect as I don't need to see those manually placed 1 values except
after an "unhide all" operation..

Is that fully clear?



[email protected]

Macro to hide rows/colums by value
 
Eliano,

Thanks, but is there a way to adapt your solution to every row and
column (or perhaps a range of 20 rows and columns) instead of A1
explicitly -- so I don't have to write multiple versions of that macro
for every column or row?

/e


On 12 Sep 2006 13:58:48 -0700, "eliano"
wrote:

Sorry.:-)

Manually ?
.EntireRow.Hidden = (.Value = "R")
.EntireColumn.Hidden = (.Value = "C")

Eliano

eliano ha scritto:

Hi friends.
Try:

Sub RunMe()
With Range("A1")
.EntireRow.Hidden = (.Value = "a")
'End With
'With Range("A1")
.EntireColumn.Hidden = (.Value = "A")
End With
End Sub

Regards,
Eliano


ha scritto:

Tom,

A4 and B6 were examples.

I'd like to be able to define the rows rows and columns to hide by
manually placing a value of 1 in cells around the perimeter of the
sheet.

I do not need execution of the hide and unhide macros hooked to any
events; I'll run them manually.

That is:

Columns: For each column I want to hide, I'll place a 1 in row 1 at
the corresponding column.

Rows: For each row I want to hide, I'll place a 1 in column A on the
corresponding row.

But the question arises: Should we hide a row or a column if user
placed 1 in A1? So I originally said I'd be happy to ignore A1. But I
now see that a 1 in A1 should hide both row 1 AND column A. That'd be
perfect as I don't need to see those manually placed 1 values except
after an "unhide all" operation..

Is that fully clear?


Tom Ogilvy

Macro to hide rows/colums by value
 
Dim Cols as Range, Rws as Range
Dim cell as Range
Rows.Hidden = False
Columns.Hidden = False
On Error Resume Next
set Cols = rows(1).SpecialCells(xlConstants,xlNumbers)
set Rws = columns(1).SpecialCells(xlConstants,xlNumbers)
On Error goto 0
if not Cols is nothing then
for each cell in cols
if cell.Value = 1 then
cell.EntireColumn.Hidden = True
end if
Next
End if
if not Rws is nothing then
for each cell in Rws
if cell.Value = 1 then
cell.EntireRow.Hidden = True
end if
next
End if

--
regards,
Tom Ogilvy



wrote in message
...
Tom,

A4 and B6 were examples.

I'd like to be able to define the rows rows and columns to hide by
manually placing a value of 1 in cells around the perimeter of the
sheet.

I do not need execution of the hide and unhide macros hooked to any
events; I'll run them manually.

That is:

Columns: For each column I want to hide, I'll place a 1 in row 1 at
the corresponding column.

Rows: For each row I want to hide, I'll place a 1 in column A on the
corresponding row.

But the question arises: Should we hide a row or a column if user
placed 1 in A1? So I originally said I'd be happy to ignore A1. But I
now see that a 1 in A1 should hide both row 1 AND column A. That'd be
perfect as I don't need to see those manually placed 1 values except
after an "unhide all" operation..

Is that fully clear?

Thanks.

/e





On Tue, 12 Sep 2006 09:37:03 -0700, Tom Ogilvy
wrote:

why a row for A4 and a column for B6?

What are your rules,

What cells should be checked.

Is this something you would do by running a macro, or do you want them to
magically hide when you enter the 1 - or is the 1 produced by calculation.

Help yourself by providing a complete explanation of what you want to do.

sub RunMe()
With Range("A4")
.EntireRow.Hidden = ( .Value = 1)
end with
With Range("B6")
.entirecolumn.Hidden = (.Value = 1)
End With
End sub




[email protected]

Macro to hide rows/colums by value
 
Thank you very much. That works exactly as I described.

/e


On Tue, 12 Sep 2006 22:37:22 -0400, "Tom Ogilvy"
wrote:

Dim Cols as Range, Rws as Range
Dim cell as Range
Rows.Hidden = False
Columns.Hidden = False
On Error Resume Next
set Cols = rows(1).SpecialCells(xlConstants,xlNumbers)
set Rws = columns(1).SpecialCells(xlConstants,xlNumbers)
On Error goto 0
if not Cols is nothing then
for each cell in cols
if cell.Value = 1 then
cell.EntireColumn.Hidden = True
end if
Next
End if
if not Rws is nothing then
for each cell in Rws
if cell.Value = 1 then
cell.EntireRow.Hidden = True
end if
next
End if



All times are GMT +1. The time now is 11:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com