+ Reply to Thread
Results 1 to 18 of 18

'Hide rows with formulas but no data' - Sheet Event Code problem

  1. #1
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi Folks,

    I've just got my first macro working!! Admittedly with code I found an another forum.

    Its this Sheet event code:

    Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    'Hide rows with formulas but no data'
    Dim cell As Range
    Application.ScreenUpdating = False
    With ActiveSheet.UsedRange
    .Rows.Hidden = False
    For Each cell In .Columns(1).SpecialCells(xlCellTypeFormulas)
    If cell.Text = "" Or cell.Value = 0 Then cell.EntireRow.Hidden = True
    Next cell
    End With
    End Sub



    This works fine for some of my worksheets as I am only interested in a single column. However on another worksheet I have 2 columns (A and H) with values returned by formulas but which are on their own row that I would like to hide if they return '0' value.

    i.e.

    A16 returns a value, then H17,18,19,20,21,22,23 also return values.

    Then back to A25 with a returned value and then H26,27,28,29,30,31,32 with returned values

    and so on and so on.


    Can the above code be adapted to 'look' in both these columns?

    Thanks very much in advance

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    It sounds like an auto filter would be a lot easier (and quicker) to me. Any reason you aren't using one?
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Try this one..

    Please Login or Register  to view this content.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi OLLY-7,

    Maybe you would like to try the attached sample WorkBook.

    It takes care of any Column with Formulas.

    Also see the "Please consider" note at the bottom of this post.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Try this .
    Change

    Please Login or Register  to view this content.

    By

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Quote Originally Posted by Debraj Roy View Post
    Try this one..

    Please Login or Register  to view this content.


    Thanks Debraj,

    This works on hiding '0' values on column A and the sub '0' values on column H but it does not hide the '0' value ' cells on column H that are 'under' a filled in values on column A.

    I.e, using my example above:


    Main Value: A16 might be 5
    so sub Values in column H break out what makes that value in A16, i.e. H17 might be '2', 18 might be '0', 19 might be '1', 20 might be '2', 21 might be '0' ,22 might be '0', 23 might be '0' .

    Then onto next set of values:

    Main Value: A25 might be 0
    Sub values: H26,27,28,29,30,31,32 = all 0 as well therefore.

    Your macro suggestion is currently removing all A25 and H26 to H32 rows but it is still showing H18, H21, H22 and H23 rows

    Any ideas?

    Thank you.

  7. #7
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    I cant download this at work (don't ask!).

    I'll try this eve and come back to you.

    Thank you.

  8. #8
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Quote Originally Posted by kvsrinivasamurthy View Post
    Try this .
    Change

    Please Login or Register  to view this content.

    By

    Please Login or Register  to view this content.

    Thanks for this kvsrinivasamurthy!

    I've tried your suggestion in Debraj's macro but it throws up a bug.

    See my comment to his post.

    Do you know what might fix this?

    Thanks very much again.

  9. #9
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Quote Originally Posted by Winon View Post
    Hi OLLY-7,

    Maybe you would like to try the attached sample WorkBook.

    It takes care of any Column with Formulas.

    Also see the "Please consider" note at the bottom of this post.


    I cant download this at work (don't ask!).

    I'll try this eve and come back to you.

    Thank you.

  10. #10
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    One more blind shot..

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Quote Originally Posted by Winon View Post
    Hi OLLY-7,

    Maybe you would like to try the attached sample WorkBook.

    It takes care of any Column with Formulas.

    Also see the "Please consider" note at the bottom of this post.

    Thanks for this Winon.

    Its pretty cool for sure only it does the opposite of what I am hopping it will do! I need all formals that return a '0' value to hide the rows and keep those that return a positive value.

    can it be tweaked to do this do you think?

    Thanks again.

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi OLLY-7,

    Thank you for the feedback.

    Sure. See this one, and let me know if you can make do with it.
    Attached Files Attached Files

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi OLLY-7,

    Oops! Haste makes waste.

    Please replace the Part Code in the Workbook with this Code below:

    Please Login or Register  to view this content.
    Sorry 'bout that, but it just works better.

  14. #14
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Sorry to sound daft - but where do I put that code?

    Cheers.

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi OLLY-7,

    No problem. See the revised attached Workbook.

    To view the Code, open the Workbook and then, hold down Alt and press F11.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    03-29-2013
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    78

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi Winon,

    Thanks very much for this. Works a treat.

    Sorry again to sound dumb, but would you be able to explain how to assign this, or any macro, to a new button on my spread sheet.

    I've been trying and not sure the correct procedure. Do I need to reference the sheet name in the macro code for each button and so have a separate macro therefor for each sheet?


    Thanks very much again. This is a massive help!



    Quote Originally Posted by Winon View Post
    Hi OLLY-7,

    No problem. See the revised attached Workbook.

    To view the Code, open the Workbook and then, hold down Alt and press F11.

  17. #17
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi OLLY-7,

    Thank you for adding to my Reputation.

    If you are satisfied with the solution I had given you, then please mark your Thread as Solved.

    Cheers.

  18. #18
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 'Hide rows with formulas but no data' - Sheet Event Code problem

    Hi OLLY-7,

    Do I need to reference the sheet name in the macro code for each button and so have a separate macro therefor for each sheet?
    Yes, if you are going to have multiple sheets which you want to access without using Sheet Tabs.

    However, if you want to use the code for Hiding/Unhiding rows you may copy the respective buttons, to any sheet of the Workbook, then in the existing code, just change Sheet1. to ActiveSheet., and the the Buttons will work on that specific Sheet, without having to amend the Code again.

    If you create a new Workbook, make sure it contains the same Code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA CODE to move rows from one sheet(1) to another sheet(2) based on data in cell
    By fozzieulo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 02:43 PM
  2. Replies: 4
    Last Post: 07-24-2012, 07:09 AM
  3. [SOLVED] Hide Sheet using Workbook Open Event
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-09-2005, 03:30 PM
  4. [SOLVED] Can't hide/unhide rows under worksheet change event?
    By Don Wiss in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2005, 07:02 PM
  5. Code Problem in BeforeSave Event
    By Kirk P. in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2005, 08:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1