PDA

View Full Version : Need Code to Unhide Rows



AIDSNGO
04-26-2012, 10:24 AM
Hi all,

I have a spreadsheet where I need a series of rows to unhide depending on the value typed into cell L68. If L68 is 1, I need rows 80-91 to unhide. If L68 is 2, I need cells 80-103 to unhide. Etc. I am a BEGINNER at this. Can someone help?

Thanks!

Bob Phillips
04-26-2012, 10:30 AM
Rows(80:200").Hidden = False 'change 200 to your last row
Select Case Range("L68").Value

Case 1: Rows("80:91").Hidden = True
Case 2: Rows("80:103").Hidden = True
'etc
End Select

chamdan
04-26-2012, 03:19 PM
Xld,
Sorry for interferring but I guess there is a mistake. Am I correct?

I guess based on what aidsngo is asking is that when the case is 1 then unhide, which results as :

Case 1: Rows("80:91").Hidden = False
Case 2: Rows("80:103").Hidden = False

Cheers!

Chuck

Bob Phillips
04-26-2012, 03:26 PM
You are right Chuck, he said unhide not hide :)

The line

Rows(80:200").Hidden = False 'change 200 to your last row

is probably (definitely!) superfluous given the real requirements.

Thanks for pointing it out.

AIDSNGO
04-27-2012, 10:04 AM
Thanks for the help, all.

I already have some code in the worksheet, and can't get what was posted to work with it:

Private Sub Worksheet_Activate()

End Sub

Private Sub Worksheet_Calculate()

End Sub



Private Sub worksheet_change(ByVal target As Excel.Range)


Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Dim ProtectStatus As Boolean

With target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
Set c = target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
On Error Resume Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
On Error GoTo 0
Application.ScreenUpdating = True
If ProtectStatus Then Me.Protect ' "password"
End If
End With
Select Case Worksheets("Instructions and Worksheet").Range("E44").Value
Case "1"
Worksheets("Activity #2").Visible = False
Worksheets("Activity #3").Visible = False
Worksheets("Activity #4").Visible = False
Case "2"
Worksheets("Activity #2").Visible = True
Worksheets("Activity #3").Visible = False
Worksheets("Activity #4").Visible = False
Case "3"
Worksheets("Activity #2").Visible = True
Worksheets("Activity #3").Visible = True
Worksheets("Activity #4").Visible = False
Case "4"
Worksheets("Activity #2").Visible = True
Worksheets("Activity #3").Visible = True
Worksheets("Activity #4").Visible = True
End Select

End Sub

Where can I put the code offered so that it won't interfere with the other Subs I have going?

Bob Phillips
04-28-2012, 05:14 AM
Are you saying you want too add the code that we gave to that code, and can't' or are you saying that code doesn't work? What does/doesn't happen?