Printable Version | Subscribe | Add to Favourites
New Topic New Poll New Reply
Author: Subject: anyone know how to hide rows or minimise group based on cell value (Excel)
mads

posted on 30/9/11 at 12:41 PM Reply With Quote
anyone know how to hide rows or minimise group based on cell value (Excel)

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





We gain knowledge faster than we do wisdom!

Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in sideways, thoroughly used, totally worn out and loudly proclaiming... "f*ck, what a trip!"

View User's Profile Visit User's Homepage View All Posts By User U2U Member
mcerd1

posted on 30/9/11 at 12:56 PM Reply With Quote
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]





-

View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 30/9/11 at 01:07 PM Reply With Quote
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





[Edited on 30/9/11 by MikeRJ]

View User's Profile View All Posts By User U2U Member
Tiger Super Six

posted on 30/9/11 at 01:08 PM Reply With Quote
If it's that simple (i.e. 'Y' and 'N' just put on auto filter and then select only 'Y' or 'N' as required?





Mark

Tiger Avon

View User's Profile View All Posts By User U2U Member
mcerd1

posted on 30/9/11 at 01:10 PM Reply With Quote
Mike's one should work better than my stupid one

it avoids the whole selection carry-on

[Edited on 30/9/2011 by mcerd1]





-

View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 30/9/11 at 01:16 PM Reply With Quote
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




Excuse the random spaces I have to put into the code to stop the stupid forum converting some of it to smileys. It's thoroughly broken in this area

View User's Profile View All Posts By User U2U Member
mcerd1

posted on 30/9/11 at 01:20 PM Reply With Quote
^^ 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]





-

View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 30/9/11 at 01:30 PM Reply With Quote
quote:
Originally posted by mcerd1
^^ you could just tick the "Disable Smilies" box...




That disables smilies for the entire post AFAIK? The forum is supposed to leave any text in a [ code ] block unformatted, so it's is genuinely broken at the moment.

There is a VBA For Dummies book that is pretty good, and the "VBA Power Programming" has just been recommended by a colleague.

You can get a reasonable idea of stuff by recording macros and then looking at the source code, and there are thousands of examples on the web if you get stuck on a particular point.

[Edited on 30/9/11 by MikeRJ]

View User's Profile View All Posts By User U2U Member
Minicooper

posted on 30/9/11 at 01:33 PM Reply With Quote
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

View User's Profile View All Posts By User U2U Member
jase380

posted on 30/9/11 at 05:11 PM Reply With Quote
Christ, you lost me with the title !!
View User's Profile View All Posts By User U2U Member
r1bob

posted on 30/9/11 at 08:49 PM Reply With Quote
quote:
Originally posted by jase380
Christ, you lost me with the title !!

View User's Profile View All Posts By User U2U Member
mads

posted on 9/10/11 at 01:44 PM Reply With Quote
thanks all. worked a treat





We gain knowledge faster than we do wisdom!

Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in sideways, thoroughly used, totally worn out and loudly proclaiming... "f*ck, what a trip!"

View User's Profile Visit User's Homepage View All Posts By User U2U Member

New Topic New Poll New Reply


go to top






Website design and SEO by Studio Montage

All content © 2001-16 LocostBuilders. Reproduction prohibited
Opinions expressed in public posts are those of the author and do not necessarily represent
the views of other users or any member of the LocostBuilders team.
Running XMB 1.8 Partagium [© 2002 XMB Group] on Apache under CentOS Linux
Founded, built and operated by ChrisW.