+ Reply to Thread
Results 1 to 3 of 3

VBA Code to Hide Rows On A Sheet Created By VBA

  1. #1
    Registered User
    Join Date
    03-10-2016
    Location
    Atlanta, GA
    MS-Off Ver
    2010
    Posts
    2

    VBA Code to Hide Rows On A Sheet Created By VBA

    I have been racking my brain for hours trying to find a solution to this issue. My goal is to hide rows 28:36 on the sheet "Inputs" if cell J24 on "Inputs" equals "No". If it equals "Yes" I want to unhide rows 28:36. My issue is that the sheet "Inputs" is created and filled by a macro so I cannot write the code onto the sheet itself, but need to either create a module that will accomplish this or write the code onto a different sheet ("Lease 1") and have it reference the sheet "Inputs". PLEASE HELP!

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: VBA Code to Hide Rows On A Sheet Created By VBA

    You could set up a Workbook_Change event, but why not just modify the code that creates the "Inputs" sheet?

    I mean there has to be a line of code that sets the value of J24 to Yes or No, so at that point, just add an if statement to unhide/hide the rows on "Inputs".

    Make sense?
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Registered User
    Join Date
    03-10-2016
    Location
    Atlanta, GA
    MS-Off Ver
    2010
    Posts
    2

    Re: VBA Code to Hide Rows On A Sheet Created By VBA

    How will that work? If the code is written into the macro that creates the sheet, then the macro will have to be re-ran each time to hide/unhide the rows. I would like for them to hide/unhide automatically if the drop down is changed from "Yes" to "No". Is there a way to code VBA to write code onto the sheet (not a separate module)? Right now I have the following code written onto the "Inputs" sheet and it functions exactly as I need it to. The problem is when I delete the sheet and re-run the macro to create it, the code goes away (obviously). I need a way for that code to be there when the sheet is recreated. Or I need a way to write this code onto a different sheet in the workbook that isn't going to be deleted and recreated by a macro. Thanks for your help!

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(False, False) = "J24" Then
    Select Case Target.Value
    Case "Yes": Rows("28:36").Hidden = False: Rows("36").Hidden = True
    Case "No": Rows("28:36").Hidden = True: Rows("36").Hidden = False
    Case Else: Rows("28:36").Hidden = True
    End Select
    End If
    End Sub

+ 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] Update VBA code - remove blank rows in newly created sheets
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2016, 03:17 PM
  2. Vb code to hide/unhide rows based on entries on another sheet
    By tcrjmom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2015, 01:15 PM
  3. 'Hide rows with formulas but no data' - Sheet Event Code problem
    By OLLY-7 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-03-2013, 04:02 AM
  4. Search row with criteria in all sheet, copy rows and paste in new created sheet
    By dekueb in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-24-2013, 01:42 PM
  5. Attach code to each sheet and if a new sheet is created add the code to this automatically
    By Irish RayRay in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-13-2012, 08:33 AM
  6. Assign code to Toolbar Created in VB to Hide Sheets and then Rehide
    By Simon Austin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-23-2009, 09:10 AM
  7. How I Apply a Excel Template in a new Sheet created in VBA Code??????
    By DjRoland in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2005, 01:34 PM

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