Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using variable to select rows in Excel 1

Status
Not open for further replies.

RodneyFAA

Technical User
Nov 20, 2006
5
US
I would like to hide (rowheight = 0) empty rows when preparing to print a spreadsheet. The following code works but I would like to replace the values (13 and 150) with variables I can identify elsewhere. Can a variable be used with "rows" or do I need to use something else? If a variable is allowed, what is the proper syntax?
 
The following code works
Which code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
My apologie..

The code that works is

Rows("13:150").Select
Selection.RowHeight = 0
 
A starting point:
Dim r1 As Long, r2 As Long
r1 = 13
r2 = 150
Rows(r1 & ":" & r2).RowHeight = 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Forgive my ignorance I am reasonably new to this, but is there any reason you did not use the Hidden functionality

Code:
Rows(r1 & ":" & r2).EntireRow.Hidden = True
 




Hi,

You might alse check out the AutoFilter Feature -- Data/AutoFilter.

Skip,

[glasses] [red][/red]
[tongue]
 
BarneyOwl --
There was not reason for not using the hidden function. Zero row height and hidden create the same result. I just needed the syntax to make it happen. Thanks

Skipvought --
Thanks for the tip on the AutoFilter. I assume it would also provide the same result. Unfortunately, I am a novice programmer, and often use a big hammer to make simple things happen.
 



"Zero row height and hidden create the same result. "

This statement is NOT true.

Zero row height and hidden APPEAR to have the same results, but the results are not identical.

The RowHeigth properties are different and the Hidden properties are different.

Its an important distinction.

Skip,

[glasses] [red][/red]
[tongue]
 
Skip,
What are the principal differences between zero height and hidden rows?

For my purposes, I merely wanted to avoid printing rows which do not contain data. The macro I am using simply "hides" (by zero height) the rows during the printing operation and then resets the height for viewing. As usual, there are probably many ways to achieve this (some more technically correct than others).

Rodney
 



Typically, RowHeight is used for Formatting Emphasis while the Hidden property is used to show or not show rows/columns of data.

Rows can be hidden via hide/unhide or by filtering. When rows are hidden, they can be progamatically detected using the SpecialCells Method.

"hiding" rows by setting the RowHeight to ZERO is a non-standard method.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top