+ Reply to Thread
Results 1 to 17 of 17

Hide rows dependant upon value of cell

  1. #1
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Hide rows dependant upon value of cell

    I have some data sitting in cells c39 to c48. Each of these cells contain a formula looking at another sheet. The returned data contains either some text or a number

    If c39 returns a number I want to hide rows 39 to 48
    If c40 returns a number I want to hide rows 40 to 48
    If c41 retuens a number I want to hide rows 41 to 48
    If c42 retuens a number I want to hide rows 42 to 48
    If c43 retuens a number I want to hide rows 43 to 48
    If c44 retuens a number I want to hide rows 44 to 48
    If c45 retuens a number I want to hide rows 45 to 48
    If c46 retuens a number I want to hide rows 46 to 48
    If c47 retuens a number I want to hide rows 47 to 48
    If c48 retuens a number I want to hide rows 48

    or I would be happy to say:
    If c39 returns a number I want to hide rows 39
    If c40 returns a number I want to hide rows 40
    If c41 retuens a number I want to hide rows 41
    If c42 retuens a number I want to hide rows 42
    If c43 retuens a number I want to hide rows 43
    If c44 retuens a number I want to hide rows 44
    If c45 retuens a number I want to hide rows 45
    If c46 retuens a number I want to hide rows 46
    If c47 retuens a number I want to hide rows 47
    If c48 retuens a number I want to hide rows 48

    The sheet already contains this VBA code

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Range("c38:c47").Rows.AutoFit
    End Sub

    and I would still need to have this on the sheet

    Im new to VBA so any help would be rally appreciated

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Hide rows dependant upon value of cell

    Are you familiar with autofilter ?
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    I am but the data is sitting on a dashboard so I dont want to have it on there. Also the data is dependant upon the value in a reference cell and will look at other feed data

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Hide rows dependant upon value of cell

    A lot depends on what "a number" actually is....... If it's the same for all rows it's easy, otherwise it starts to get more complicated

  5. #5
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    I could set it as any number really. Presently the numbers are limited to 1-10

  6. #6
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Hide rows dependant upon value of cell

    Hi
    Right click on the Tab you want this action to take place and click on "View Code". Then cut and paste the folling code onto the sheet exactly as is and save and close the sheet:

    Private Sub Worksheet_Change(ByVal Target As Range)
    '
    '
    'Check Cell C39 for numeic Value
    If IsNumeric(C39) Then
    Rows("39:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C40 for numeic Value
    If IsNumeric(C40) Then
    Rows("40:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C39 for numeic Value
    If IsNumeric(C39) Then
    Rows("41:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C42 for numeic Value
    If IsNumeric(C39) Then
    Rows("42:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C43 for numeic Value
    If IsNumeric(C39) Then
    Rows("43:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C44 for numeic Value
    If IsNumeric(C39) Then
    Rows("44:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C45 for numeic Value
    If IsNumeric(C39) Then
    Rows("45:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C46 for numeic Value
    If IsNumeric(C39) Then
    Rows("46:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C47 for numeic Value
    If IsNumeric(C39) Then
    Rows("47:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C48 for numeic Value
    If IsNumeric(C39) Then
    Rows("48:48").Select
    Selection.EntireRow.Hidden = True
    End If
    End Sub

    Let me know how you get on.
    Good luck.
    Tony

  7. #7
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Hide rows dependant upon value of cell

    What happens if c42 isn't numeric but C39 is

    do you want to show 42 or not?

  8. #8
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    I pasted your code but for some reason it doesnt seem to work . For info - not sure how relevant - I have changed the cell formats to number and am working in a macro enabled 2010 work sheet

  9. #9
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    Any - Yes I would if c42 isn't numeric but C39 is I would want to show row 42

  10. #10
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Hide rows dependant upon value of cell

    Quote Originally Posted by spoursy View Post
    I pasted your code but for some reason it doesnt seem to work . For info - not sure how relevant - I have changed the cell formats to number and am working in a macro enabled 2010 work sheet
    Hi
    Make sure you posted the code behind the Worksheet (right click on the Tab and select View Code) and NOT in a module. It works perfectly well on the sample document you posted earlier. I am also using a macro Enabled Workbook in excel 2010.
    Tony
    Last edited by ARGK; 05-09-2013 at 06:48 AM.

  11. #11
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    I have attached my spreadsheet to this email

    The sheet where the data is is called DASH-Department(1)
    There is a cell (j6) which provides an indirect function to change some of the data - dont know if this is relevant

    Many thanks for your help
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Hide rows dependant upon value of cell

    Hi
    Firstly the code wont run because you have Macro's disabled in your workbook. You need to enable macros. Secondly there were a fewq errors in the code I provided you so please replace with the code below:

    Private Sub Worksheet_Change(ByVal Target As Range)
    '
    '
    'Check Cell C39 for numeic Value
    If IsNumeric(C39) Then
    Rows("39:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C40 for numeic Value
    If IsNumeric(C40) Then
    Rows("40:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C41 for numeic Value
    If IsNumeric(C41) Then
    Rows("41:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C42 for numeic Value
    If IsNumeric(C42) Then
    Rows("42:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C43 for numeic Value
    If IsNumeric(C43) Then
    Rows("43:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C44 for numeic Value
    If IsNumeric(C44) Then
    Rows("44:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C45 for numeic Value
    If IsNumeric(C45) Then
    Rows("45:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C46 for numeic Value
    If IsNumeric(C46) Then
    Rows("46:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C47 for numeic Value
    If IsNumeric(C47) Then
    Rows("47:48").Select
    Selection.EntireRow.Hidden = True
    End If
    'Check Cell C48 for numeic Value
    If IsNumeric(C48) Then
    Rows("48:48").Select
    Selection.EntireRow.Hidden = True
    End If
    End Sub

    Good luck.
    Tony

  13. #13
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    Tony

    Thanks for all your help but Im still not getting anywhere with this - Ive changed the Macro settings and they are enabled. Roger

  14. #14
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Hide rows dependant upon value of cell

    Hi Roger
    Please check your private messages.
    Tony

  15. #15
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Hide rows dependant upon value of cell

    Hi Roger
    Please replace the current code with the code in the attached file and let me know how you get on.
    Good luck.
    Tony
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    Ill give this a go when Im back at my desk

    Thanks

  17. #17
    Registered User
    Join Date
    07-13-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Hide rows dependant upon value of cell

    Tony

    I think we're getting there. The code works but only when i turn the auto caluculation to manual. When its on automatic the screen 'flashes' as it is calculating iver and over again and the programme crashes as a result

    Any ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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