Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 28
Default Writing a macro to hide columns based on cell value

I'm trying to write a macro that will automatically hide certain columns
based on a cell's value. Basically, if C3 = "Sales" I need columns R, S, and
T to be hiden; however if C3 does not equal "Sales" i need columns L, M and N
to be hiden, but R, S, and T need to come back into view and vice versa. Is
there a macro that can assist me? Please help. Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default Writing a macro to hide columns based on cell value

Right click on sheet tab, view code, and paste appropriate macro in.
If C3 is controlled by formula:

Private Sub Worksheet_Calculate()

If Range("c3").Value = "Sales" Then
Columns("R:T").EntireColumn.Hidden = True
Columns("L:N").EntireColumn.Hidden = False
Else
Columns("R:T").EntireColumn.Hidden = False
Columns("L:N").EntireColumn.Hidden = True
End If

End Sub


If inputted manually:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("C3") Then
If Range("c3").Value = "Sales" Then
Columns("R:T").EntireColumn.Hidden = True
Columns("L:N").EntireColumn.Hidden = False
Else
Columns("R:T").EntireColumn.Hidden = False
Columns("L:N").EntireColumn.Hidden = True
End If
End If

End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"JAbels001" wrote:

I'm trying to write a macro that will automatically hide certain columns
based on a cell's value. Basically, if C3 = "Sales" I need columns R, S, and
T to be hiden; however if C3 does not equal "Sales" i need columns L, M and N
to be hiden, but R, S, and T need to come back into view and vice versa. Is
there a macro that can assist me? Please help. Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 28
Default Writing a macro to hide columns based on cell value

Worked like a charm! Thanks!

"Luke M" wrote:

Right click on sheet tab, view code, and paste appropriate macro in.
If C3 is controlled by formula:

Private Sub Worksheet_Calculate()

If Range("c3").Value = "Sales" Then
Columns("R:T").EntireColumn.Hidden = True
Columns("L:N").EntireColumn.Hidden = False
Else
Columns("R:T").EntireColumn.Hidden = False
Columns("L:N").EntireColumn.Hidden = True
End If

End Sub


If inputted manually:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("C3") Then
If Range("c3").Value = "Sales" Then
Columns("R:T").EntireColumn.Hidden = True
Columns("L:N").EntireColumn.Hidden = False
Else
Columns("R:T").EntireColumn.Hidden = False
Columns("L:N").EntireColumn.Hidden = True
End If
End If

End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"JAbels001" wrote:

I'm trying to write a macro that will automatically hide certain columns
based on a cell's value. Basically, if C3 = "Sales" I need columns R, S, and
T to be hiden; however if C3 does not equal "Sales" i need columns L, M and N
to be hiden, but R, S, and T need to come back into view and vice versa. Is
there a macro that can assist me? Please help. Thanks!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic Hide group of a columns based on cel value Rechie Excel Discussion (Misc queries) 5 July 16th 08 08:43 PM
Macro to Hide rows based on value of column F Scott Marcus Excel Discussion (Misc queries) 10 October 27th 06 11:57 PM
Is there a way to hide worksheets and/or rows/columns based on information enter into a particular cell of range of cells? Marc New Users to Excel 1 March 10th 06 05:10 PM
Formula or Macro to hide a row based on a cell value JP Excel Discussion (Misc queries) 0 February 3rd 06 06:10 PM
How do I automatically hide columns in a worksheet based on a cell value? dkhedkar Excel Worksheet Functions 1 March 5th 05 12:20 AM


All times are GMT +1. The time now is 11:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"