hey up all,
I think the sun is getting to me a little and cant work out how to write the VBA code to do the following:
If cell value of H10 = Y
then rows 14 - 24 are visible
If cell value of H10 = N
then rows 14 - 24 are hidden
I can group the rows together if that makes it easier and then the group just needs to be minimised based on the users value in cell H10
Cheers,
mads
my memory of VBA is not so good (its been more than 8 years since I had to use it)
but I aways uesd to record a macro on a dummy sheet/woorkbook - steal the bit of code and modify it to suit
so I've just recorded a wee macro of me hideing a selected row / column and this is what I got:
Rows("28:29").Select
Selection.EntireRow.Hidden = True
Columns("H:J").Select
Selection.EntireColumn.Hidden = True
so you just need to get it to sellect the rows when your condition is met and use the command above to hide the selection.... (if x = y then select
row z and so on...... )
[Edited on 30/9/2011 by mcerd1]
Excuse the stupid 'code' formatting - I wish Chris would disable double spacing and make it ignore VB code like smileys.
code:
Sub HideRows()
Dim i As Integer
Dim hideState As Boolean
hideState = (UCase(Cells(10, 8).Value) = "Y" )
For i = 14 To 24
Cells(i).EntireRow.Hidden = hideState
Next
End Sub
If it's that simple (i.e. 'Y' and 'N' just put on auto filter and then select only 'Y' or 'N' as required?
Mike's one should work better than my stupid one
it avoids the whole selection carry-on
[Edited on 30/9/2011 by mcerd1]
Actualy mines pretty stupid now I've thought about it, using ranges is a lot simpler!
code:
Sub HideRows()
Range("A14:A24" ).EntireRow.Hidden = (UCase(Range("H10" ).Text) = "Y" )
End Sub
^^ you could just tick the "Disable Smilies" box...
going marganaly off topic - does anyone have any idiots guide websites / books they'd recommend for someone to learn VBA ?
(I'm going to have to use it again soon, but I can hardly remember any of it )
[Edited on 30/9/2011 by mcerd1]
quote:
Originally posted by mcerd1
^^ you could just tick the "Disable Smilies" box...
My turn
Sub HideUnhideRows()
If UCase(Range("H10" ).Value) = "Y" Then
Rows("14:24" ).EntireRow.Hidden = False
End If
If UCase(Range("H10" ).Value) = "N" Then
Rows("14:24" ).EntireRow.Hidden = True
End If
End Sub
David
Christ, you lost me with the title !!
quote:
Originally posted by jase380
Christ, you lost me with the title !!
thanks all. worked a treat