+ Reply to Thread
Results 1 to 2 of 2

VBA Row Hiding Code Not Responding As Expected

Hybrid View

  1. #1
    Registered User
    Join Date
    04-20-2021
    Location
    London, England
    MS-Off Ver
    Office 2016
    Posts
    5

    VBA Row Hiding Code Not Responding As Expected

    Hello.

    I'm currently using VBA which is aimed at a Cell, B5. Once the Cell updates the code below hides or un-hides rows. However the section for CPC 0700000 does not want to do anything, but the code for CPC 4000000 and 7100000 works perfectly.
    Can anyone point me in the direction of why this is not working as I expect it to?

    Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.Activate
    If Not Application.Intersect(Range("B5"), Range(Target.Address)) Is Nothing Then
    Select Case Target.Value
    Case Is = "CPC 4000000": Rows("30:35").EntireRow.Hidden = True
    Rows("36").EntireRow.Hidden = False
    Rows("37:39").EntireRow.Hidden = True
    Rows("43:44").EntireRow.Hidden = False
    Case Is = "CPC 0700000": Rows("32:36").EntireRow.Hidden = True
    Rows("30:39").EntireRow.Hidden = False
    Rows("43:44").EntireRow.Hidden = False
    Case Is = "CPC 7100000": Rows("30:35").EntireRow.Hidden = False
    Rows("36:39").EntireRow.Hidden = True
    Rows("43:44").EntireRow.Hidden = True
    End Select
    End If
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,951

    Re: VBA Row Hiding Code Not Responding As Expected

    Check the sequence of events here:

            Rows("32:36").EntireRow.Hidden = True    ' hide
            Rows("30:39").EntireRow.Hidden = False   ' unhide
            Rows("43:44").EntireRow.Hidden = False   ' unhide
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    ' ActiveSheet.Activate  ' this is redundant
    
    If Not Application.Intersect(Range("B5"), Target) Is Nothing Then
        Select Case Target.Value
        Case Is = "CPC 4000000"
            Rows("30:35").EntireRow.Hidden = True
            Rows("36").EntireRow.Hidden = False
            Rows("37:39").EntireRow.Hidden = True
            Rows("43:44").EntireRow.Hidden = False
        Case Is = "CPC 0700000"
            Rows("30:39").EntireRow.Hidden = False
            Rows("43:44").EntireRow.Hidden = False
            Rows("32:36").EntireRow.Hidden = True
        Case Is = "CPC 7100000"
            Rows("30:35").EntireRow.Hidden = False
            Rows("36:39").EntireRow.Hidden = True
            Rows("43:44").EntireRow.Hidden = True
        End Select
    End If
    
    End Sub
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. [SOLVED] why the code is not responding on the second sheet?
    By sumesh56 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-29-2022, 12:30 PM
  2. [SOLVED] ListBox and ComboBox in UserForm not responding to code
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-13-2020, 10:10 AM
  3. Command buttons despite VBA code are not responding.
    By numberonelevelit in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-11-2020, 05:13 PM
  4. Code stall at .Pictures.Insert URL - server not responding?
    By PeterBundeHansen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-16-2017, 12:19 PM
  5. [SOLVED] Hiding column causes VBA code to behave not as expected
    By kampatel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2016, 05:50 PM
  6. [SOLVED] Non Responding Excel Workbook VBA Code
    By Bezzie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-26-2015, 11:33 AM
  7. [SOLVED] Excel not responding, for this code.
    By dinakar.yadav in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-10-2014, 08:33 AM

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