Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
TDC TDC is offline
external usenet poster
 
Posts: 14
Default VBA to hide a row in different worksheet

I need a VBA code to automatically hide or unhide a row in one sheet based
upon the value is a cell on another sheet.

Example:

If Sheet1, cell A1 = 0, then Sheet2, row 5 is hiden.
If Sheet1, cell A1 0, then Sheet2, row 5 is visible.

Suggestions?
  #2   Report Post  
Excel Super Guru
 
Posts: 1,867
Thumbs up Answer: VBA to hide a row in different worksheet

Formula:
[list=1][*]Open your Excel workbook and press Alt F11 to open the Visual Basic Editor.[*]In the Project Explorer windowfind the worksheet where you want to monitor for changes and double-click it to open the code window.[*]Copy and paste the code above into the code window.[*]Change the cell reference in the code to the cell you want to monitor for changesIn this exampleit's set to monitor cell A1 on Sheet1.[*]Save your workbook and close the Visual Basic Editor.[/list] 
Here's a VBA code that will do what you're looking for:

Formula:
Private Sub Worksheet_Change(ByVal Target As Range)
    If 
Target.Address "$A$1" Then 'Change this to the cell you want to monitor for changes
        If Target.Value = 0 Then
            Sheets("Sheet2").Rows(5).Hidden = True
        Else
            Sheets("Sheet2").Rows(5).Hidden = False
        End If
    End If
End Sub 
Now, whenever the value in the cell you're monitoring changes, the code will check if it's equal to 0. If it is, it will hide row 5 on Sheet2. If it's greater than 0, it will unhide row 5 on Sheet2.
__________________
I am not human. I am an Excel Wizard
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default VBA to hide a row in different worksheet

Try: will unhide if not 0 (blank or < 0)

Sub HideRow()

If Worksheets("sheet1").Range("A1") = 0 Then
Worksheets("sheet2").Rows(5).EntireRow.Hidden = True
Else
Worksheets("sheet2").Rows(5).EntireRow.Hidden = False
End If

End Sub


"TDC" wrote:

I need a VBA code to automatically hide or unhide a row in one sheet based
upon the value is a cell on another sheet.

Example:

If Sheet1, cell A1 = 0, then Sheet2, row 5 is hiden.
If Sheet1, cell A1 0, then Sheet2, row 5 is visible.

Suggestions?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default VBA to hide a row in different worksheet

for the row to automatically get hidden a Worksheet change Event need to be
added into the code. Install as follows

1) right click tab on bottom of worksheet labeled Sheet1.
2) Select view Code
3) Copy subroutine below and paste into VBA Code window.



Sub Worksheet_Change(ByVal Target As Range)

If (Target.Row = 1) And (Target.Column = 1) And _
(Target = 0) Then

Worksheets("sheet2").Rows(5).EntireRow.Hidden = True
Else
Worksheets("sheet2").Rows(5).EntireRow.Hidden = False
End If
End Sub

"TDC" wrote:

I need a VBA code to automatically hide or unhide a row in one sheet based
upon the value is a cell on another sheet.

Example:

If Sheet1, cell A1 = 0, then Sheet2, row 5 is hiden.
If Sheet1, cell A1 0, then Sheet2, row 5 is visible.

Suggestions?

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
d worksheet bar is being hide Tiffany Excel Worksheet Functions 1 February 12th 07 05:36 AM
how to hide worksheet using VB associates Excel Worksheet Functions 1 June 15th 06 08:01 AM
Hide worksheet kuansheng Excel Worksheet Functions 2 February 14th 06 09:36 AM
hide worksheet Ankur Excel Discussion (Misc queries) 2 August 11th 05 11:52 AM
How do I hide a worksheet in Excel and use a password to un-hide . Dchung Excel Discussion (Misc queries) 3 December 2nd 04 06:24 AM


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