Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hiding rows with zero values

I really liked this example because it is extremly effecient when
hiding zero values in a given column, but I was wondering if I could
get some help in modifying this example for when the column is unknown
but has been selected. The reason I ask is I would like to use this
feature on several different spreadsheets, but I would like to be able
to use the same macro without having to modify it each time.

Thank you!!!!

Sub UnionExample()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range


With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = StartRow To EndRow Step 1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in
the cell
ElseIf .Cells(Lrow, "A").Value = "0" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "A")
Else
Set rng = Application.Union(rng, .Cells(Lrow,
"A"))
End If
End If
Next
End With
'hide all rows in one time
If Not rng Is Nothing Then rng.EntireRow.Hidden = True


With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Hiding rows with zero values

try adding these 2 lines:

Dim colnum As Long
colnum = ActiveCell.Column

then where you explicitly use column "A":
(Lrow, "A")

use:
(Lrow,colnum)

give that a try
--


Gary


wrote in message
...
I really liked this example because it is extremly effecient when
hiding zero values in a given column, but I was wondering if I could
get some help in modifying this example for when the column is unknown
but has been selected. The reason I ask is I would like to use this
feature on several different spreadsheets, but I would like to be able
to use the same macro without having to modify it each time.

Thank you!!!!

Sub UnionExample()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range


With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = StartRow To EndRow Step 1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in
the cell
ElseIf .Cells(Lrow, "A").Value = "0" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "A")
Else
Set rng = Application.Union(rng, .Cells(Lrow,
"A"))
End If
End If
Next
End With
'hide all rows in one time
If Not rng Is Nothing Then rng.EntireRow.Hidden = True


With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Hiding rows with zero values

Sub UnionExample()
Dim Lrow As Long
Dim LCol As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range
Dim cell As Range

Set cell = Application.InputBox("Select target column with mouse",
Type:=8)
If Not cell Is Nothing Then

LCol = cell.Column

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = StartRow To EndRow Step 1
If IsError(.Cells(Lrow, LCol).Value) Then
'Do nothing, This avoid a error if there is a error in
the cell
ElseIf .Cells(Lrow, LCol).Value = "0" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, LCol)
Else
Set rng = Application.Union(rng, .Cells(Lrow, LCol))
End If
End If
Next

'hide all rows in one time
If Not rng Is Nothing Then rng.EntireRow.Hidden = True
End With

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End If
End Sub


--
HTH

Bob

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

wrote in message
...
I really liked this example because it is extremly effecient when
hiding zero values in a given column, but I was wondering if I could
get some help in modifying this example for when the column is unknown
but has been selected. The reason I ask is I would like to use this
feature on several different spreadsheets, but I would like to be able
to use the same macro without having to modify it each time.

Thank you!!!!

Sub UnionExample()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range


With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = StartRow To EndRow Step 1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in
the cell
ElseIf .Cells(Lrow, "A").Value = "0" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "A")
Else
Set rng = Application.Union(rng, .Cells(Lrow,
"A"))
End If
End If
Next
End With
'hide all rows in one time
If Not rng Is Nothing Then rng.EntireRow.Hidden = True


With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
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
Hiding Specific Rows Based on Values in Other Rows Chris Excel Worksheet Functions 1 November 2nd 06 08:21 PM
Hiding a button when hiding rows fergusor Excel Discussion (Misc queries) 2 August 10th 06 02:31 PM
Automatically hiding rows with specific values Daria Excel Programming 3 January 18th 06 03:18 AM
Hiding Rows with Zero or Blank Values Robin Excel Programming 0 July 30th 03 11:42 PM
Hiding Rows with Zero or Blank Values Robert Black Excel Programming 0 July 30th 03 11:21 PM


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