Results 1 to 3 of 3

VBA to hide cells based on dropdown list using If/Else/Then

Threaded View

  1. #1
    Registered User
    Join Date
    07-30-2012
    Location
    Farmington, New Mexico
    MS-Off Ver
    Excel 2010
    Posts
    14

    VBA to hide cells based on dropdown list using If/Else/Then

    Hello,

    Thanks for your time. I am currently trying to write a VBA that will hide a RANGE of cells based on the value of a drop down list. I.E., my dropdown list is in C18 and contains a list of 0-6 (number of dents). So, if the user selects say 2 dents, I want to hide cells A28:C43 (dent dimensions-an entire block of cells). I have a VBA written, but as of right now it is hiding the entire column, and I haven't figure out how to edit it for a range of cells and not just the column. Here is my code

    Private Sub ComboBox1_Change()
    
     If Range("C18").Value = "0" Then
     Range("C19:C43").EntireColumn.Hidden = True
     ElseIf Range("C18").Value = "1" Then
     Range("C19:C23").EntireColumn.Hidden = False
     Range("C23:C43").EntireColumn.Hidden = True
     ElseIf Range("C18").Value = "2" Then
     Range("C19:C27").EntireColumn.Hidden = False
     Range("C28:C43").EntireColumn.Hidden = True
     ElseIf Range("C18").Value = "3" Then
     Range("C19:C31").EntireColumn.Hidden = False
     Range("C32:C43").EntireColumn.Hidden = True
     ElseIf Range("C18").Value = "4" Then
     Range("C19:C35").EntireColumn.Hidden = False
     Range("C36:C43").EntireColumn.Hidden = True
     ElseIf Range("C18").Value = "5" Then
     Range("C19:C39").EntireColumn.Hidden = False
     Range("C40:C43").EntireColumn.Hidden = True
     ElseIf Range("C18").Value = "6" Then
     Range("C19:C43").EntireColumn.Hidden = False
     End If
     
     End Sub

    If this is not enough information required, please let me know.
    Any help will be much appreciated. Thanks!

    ---------- Post added at 10:47 AM ---------- Previous post was at 09:58 AM ----------

    Is this even possible? When using Format>Visibility>Hide and Unhide, there is not option for hiding cells I know, but I'm hoping there's a way to put bounds on entirecolumn.hidden/entirerow.hidden.

    Thanks again.
    Attached Files Attached Files
    Last edited by JOHNROK; 07-30-2012 at 06:11 PM. Reason: added attachment

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