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

Hi all,

Need some quick help.

When I run a simulation it generates 10 rows of data for years 1987(row1) to
2002(row16) which is placed into sheet2 of the workbook.

I want the macro to look at sheet1,cell A1, say this has year 1995 in the
cell, and when I press the macro button this would hide rows 1987 up to 1994
and therefore display only 1995 to 2002.

So the only variable is cell A1 i.e. 1995

Thanks in advance to anyone's help

Pantelis


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Hide rows with VBA

Sub HideRows()
Rows.Hidden = False

Range(Cells(1,1),ActiveCell.Offset(-1,0)).EntireRow.Hidden = True
End Sub

Assign that to my button (forms toolbar or menu button) or put similar code
in the click event for a commandbarbutton.
--
Regards,
Tom Ogilvy

"pantelis" wrote in message
...
Hi all,

Need some quick help.

When I run a simulation it generates 10 rows of data for years 1987(row1)

to
2002(row16) which is placed into sheet2 of the workbook.

I want the macro to look at sheet1,cell A1, say this has year 1995 in the
cell, and when I press the macro button this would hide rows 1987 up to

1994
and therefore display only 1995 to 2002.

So the only variable is cell A1 i.e. 1995

Thanks in advance to anyone's help

Pantelis




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Hide rows with VBA

Tom,

Thanks again for your quick answers, does work but only for the active cell,
when refering to another cell what do I do
this is soemthing i put together but id does not work

Sub HideRows()

Dim Rownumber As Integer
Sheets("Shee1").Cells(1, 6).Value = Rownumber
Rows.Hidden = False
Range(Cell(4, 1), Cell(Rownumber - 1, 1)).EntireRow.Hidden = True
End Sub

Would appreciate your help
Pantelis



"Tom Ogilvy" wrote in message
...
Sub HideRows()
Rows.Hidden = False

Range(Cells(1,1),ActiveCell.Offset(-1,0)).EntireRow.Hidden = True
End Sub

Assign that to my button (forms toolbar or menu button) or put similar

code
in the click event for a commandbarbutton.
--
Regards,
Tom Ogilvy

"pantelis" wrote in message
...
Hi all,

Need some quick help.

When I run a simulation it generates 10 rows of data for years

1987(row1)
to
2002(row16) which is placed into sheet2 of the workbook.

I want the macro to look at sheet1,cell A1, say this has year 1995 in

the
cell, and when I press the macro button this would hide rows 1987 up to

1994
and therefore display only 1995 to 2002.

So the only variable is cell A1 i.e. 1995

Thanks in advance to anyone's help

Pantelis






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Hide rows with VBA

Sorry, misread the question.

Sub HideRows()
Dim yr As Long
Dim numRows As Long
yr = Worksheets("Sheet1").Cells(1, 1)
If yr < 1987 Then Exit Sub
numRows = yr - 1987
With Worksheets("Sheet2")
.Rows.Hidden = False
.Cells(1, 1).Resize(numRows).EntireRow.Hidden = True
End With
End Sub


--
Regards,


"pantelis" wrote in message
...
Tom,

Thanks again for your quick answers, does work but only for the active

cell,
when refering to another cell what do I do
this is soemthing i put together but id does not work

Sub HideRows()

Dim Rownumber As Integer
Sheets("Shee1").Cells(1, 6).Value = Rownumber
Rows.Hidden = False
Range(Cell(4, 1), Cell(Rownumber - 1, 1)).EntireRow.Hidden = True
End Sub

Would appreciate your help
Pantelis



"Tom Ogilvy" wrote in message
...
Sub HideRows()
Rows.Hidden = False

Range(Cells(1,1),ActiveCell.Offset(-1,0)).EntireRow.Hidden = True
End Sub

Assign that to my button (forms toolbar or menu button) or put similar

code
in the click event for a commandbarbutton.
--
Regards,
Tom Ogilvy

"pantelis" wrote in message
...
Hi all,

Need some quick help.

When I run a simulation it generates 10 rows of data for years

1987(row1)
to
2002(row16) which is placed into sheet2 of the workbook.

I want the macro to look at sheet1,cell A1, say this has year 1995 in

the
cell, and when I press the macro button this would hide rows 1987 up

to
1994
and therefore display only 1995 to 2002.

So the only variable is cell A1 i.e. 1995

Thanks in advance to anyone's help

Pantelis








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
Group rows (or hide rows) like in MS Project Annie1904 Excel Worksheet Functions 2 October 17th 09 05:15 AM
Macro code to hide rows and not calculate hidden rows bradmcq Excel Discussion (Misc queries) 0 September 1st 09 12:38 AM
Enabling option „Format rows“ to hide/unhide rows using VBA-code? ran58 Excel Discussion (Misc queries) 0 July 28th 09 03:46 PM
cut rows without cutting hide rows מיכל Excel Discussion (Misc queries) 1 June 25th 07 02:01 PM
Hide Rows - copy and paste only rows that show Access101 Excel Worksheet Functions 3 March 1st 06 12:39 AM


All times are GMT +1. The time now is 01:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"