Macro to select cells at current cell

C

cvgairport

Hi there,

Can a VB macro be written to hide 3 rows at the cell position - no matter
where the current cell position is. I can write a macro to select specific
row numbers, but I want one that will take the 3 rows from the current cell.

Thanks!

Amy
 
E

excel-ant

Hi Amy,

You certainly can
==========================================
Sub Hide3Rows()

qrow = ActiveCell.Row
Rows(qrow & ":" & qrow + 2).EntireRow.Hidden = True

End Sub
==========================================
Ant
http://www.excel-ant.co.uk
 
L

Lars-Åke Aspelin

Hi there,

Can a VB macro be written to hide 3 rows at the cell position - no matter
where the current cell position is. I can write a macro to select specific
row numbers, but I want one that will take the 3 rows from the current cell.

Thanks!

Amy



Try this

Selection.Resize(3, 1).EntireRow.Hidden = True

This will hide the (top) row of the current selection together with
the two following rows.

Hope this helps / Lars-Åke
 
C

cvgairport

that's just it - it varies everytime I would want to execute the macro. I
want to hide a 3 row tall comment section from a deaprtmental expense
analysis. It is a listing of accounts with comment boxes under each. I want
to print the spreadhseet with the comment boxes hidden. I want to move down
the spreadsheet and execute the macro to hide the comment box wherever I find
them so the row numbers differ each time I execute the macro.
 
L

Lars-Åke Aspelin

Try this

Selection.Resize(3, 1).EntireRow.Hidden = True

This will hide the (top) row of the current selection together with
the two following rows.

Hope this helps / Lars-Åke

The above formula can be shortened a bit

Selection.Resize(3, 1).Rows.Hidden = True

Lars-Åke
 
G

Gary Keramidas

what i meant was the rows above or below the active cell.

rows(activecell.Row).resize(2).entirerow.hidden=true
 
G

Gary Keramidas

but you wanted 3 rows, not 2 as in my previous post

rows(activecell.Row).resize(3).entirerow.hidden=true
 
L

Lars-Åke Aspelin

The above formula can be shortened a bit

Selection.Resize(3, 1).Rows.Hidden = True

Lars-Åke

Even shorter :)

Selection.Resize(3).Rows.Hidden = True

Lars-Åke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top