+ Reply to Thread
Results 1 to 7 of 7

I need to hide column f or column g based on text in cell b2

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    I need to hide column f or column g based on text in cell b2

    Hi,
    I need to hide column f or column g based on text in cell b2, I would like the 2 column to auto switch if possible please.

    If "B2" contains "Darrell" so hide column "G" and un hide column "F".
    If "B2" contains "Brendon" hide column "F" and un hide column "G".
    If "B2" is empty un hide "F" & "G"

    Any help is always much appreciated.

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: I need to hide column f or column g based on text in cell b2

    This is so easy I'm wondering why you're asking. You can turn on the macro recorder and hide / unhide columns F & G.,...and then put an If range("B2").value =......statement to do the rest.

    If you're not sure about how to use the macro recorder or what an If statement is then I suggest starting here: http://www.excelforum.com/excel-prog...materials.html
    Last edited by BellyGas; 08-03-2015 at 09:06 AM.

  3. #3
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: I need to hide column f or column g based on text in cell b2

    It's only that easy when you know how! Thanks for the link.

  4. #4
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: I need to hide column f or column g based on text in cell b2

    I think this should do it.

    Here is the code itself:
    Sub Hide_Unhide()
        
    If Cells(2, "B").Value = "Darrel" Then
    
        Columns("G").Hidden = True
        Columns("F").Hidden = False
        
    Else
        
        If Cells(2, "B").Value = "Brendon" Then
        
            Columns("G").Hidden = False
            Columns("F").Hidden = True
            
        Else
        
            If Cells(2, "B").Value = nul Then
            
                Columns("G").Hidden = False
                Columns("F").Hidden = False
                
            Else
            End If
        End If
    End If
            
         
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: I need to hide column f or column g based on text in cell b2

    Many thanks bmouse, brilliant!

  6. #6
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: I need to hide column f or column g based on text in cell b2

    Here's a similar version that will do the task automatically when cell B2 is changed.
    By using SELECT / CASE structure instead of IF / ELSEIF, you can easily add more values if needed.
    Place this in the code section for the sheet you are working with.

    Private Sub Worksheet_Change(ByVal Target As Range)
      ' For Excel Forum, Aug 3, 2015; user A440. 
      '   I need to hide column f or column g based on text in cell b2, I would like the 2 column to auto switch if possible please.
      '   If "B2" contains "Darrell" so hide column "G" and un hide column "F".
      '   If "B2" contains "Brendon" hide column "F" and un hide column "G".
      '   If "B2" is empty un hide "F" & "G"
      
      If Intersect(Target, Range("B2")) Is Nothing Then Exit Sub
      Application.EnableEvents = False
      
      Select Case Target
      
        Case Is = "Darrell"
          Columns("G").Hidden = True
          Columns("F").Hidden = False
          
        Case Is = "Brendon"
          Columns("G").Hidden = False
          Columns("F").Hidden = True
          
        Case Else
          Columns("G").Hidden = False
          Columns("F").Hidden = False
          
      End Select
      
      Application.EnableEvents = True
    End Sub
    If this has been helpful, please click on the star at the left.

  7. #7
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: I need to hide column f or column g based on text in cell b2

    Thank you very much StuCram this is exactly what I wonted.

+ 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] Need a formula to change cell in column 2 based off of text in column 1
    By bevwalker in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-30-2014, 03:26 PM
  2. Replies: 1
    Last Post: 01-30-2014, 01:42 PM
  3. [SOLVED] Fill a cell in Column B based on the text in Column A using a table on sheet 2
    By lbrasfie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-25-2013, 01:56 PM
  4. Trying to hide row and column based on cell value
    By deef73 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2013, 07:24 AM
  5. Hide column based on the value of the 1st cell in it
    By raehippychick in forum Excel General
    Replies: 2
    Last Post: 06-28-2007, 08:04 AM
  6. [SOLVED] Hide column or row based on a cell in the column or row?
    By SacGuy in forum Excel General
    Replies: 0
    Last Post: 01-24-2006, 02:55 PM
  7. [SOLVED] Hide Column - With text in cell
    By O&O in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2005, 09:10 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