Home |
Search |
Today's Posts |
|
#1
|
|||
|
|||
Hiding cells on condition
I am trying to hide a range of cells when the value in another cell is FALSE
and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#2
|
|||
|
|||
Apart from syntax errors, you can only hide an entirecolumn or row.
-- HTH RP (remove nothere from the email address if mailing direct) "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#3
|
|||
|
|||
Hi..
Private Sub Workbook_Open() With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#4
|
|||
|
|||
simpler
Private Sub Workbook_Open() Sheets("Sheet1").Range("E3:M3").EntireColumn.Hidde n = Not .Range("C4").Value End Sub -- HTH RP (remove nothere from the email address if mailing direct) "William" wrote in message ... Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") .Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ .Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#6
|
|||
|
|||
Willaim
I inserted Private Sub Workbook_Open() With Sheets("ProcessA").Range("E3:M3").EntireColumn.Hid den = Not ..Range("C4").Value = False End With But VBA does not like .Range I am using Excel 2000. Also if one can only hide complete rows or columns why is the range ("E3:M3")? "William" wrote: Very nice Bob! For the benefit of the OP, I think you intended.... With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = Not .Range("C4").Value End With Note: C4 must contain either TRUE or FLASE (or be blank). -- ----- XL2003 Regards William "Bob Phillips" wrote in message ... simpler Private Sub Workbook_Open() Sheets("Sheet1").Range("E3:M3").EntireColumn.Hidde n = Not .Range("C4").Value End Sub -- HTH RP (remove nothere from the email address if mailing direct) "William" wrote in message ... Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") .Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ .Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#7
|
|||
|
|||
The lines have got mixed up.
Try Private Sub Workbook_Open() With Sheets("ProcessA") .Range("E3:M3").EntireColumn.Hidden = _ Not .Range("C4").Value = False End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Pennington" wrote in message ... Willaim I inserted Private Sub Workbook_Open() With Sheets("ProcessA").Range("E3:M3").EntireColumn.Hid den = Not .Range("C4").Value = False End With But VBA does not like .Range I am using Excel 2000. Also if one can only hide complete rows or columns why is the range ("E3:M3")? "William" wrote: Very nice Bob! For the benefit of the OP, I think you intended.... With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = Not .Range("C4").Value End With Note: C4 must contain either TRUE or FLASE (or be blank). -- ----- XL2003 Regards William "Bob Phillips" wrote in message ... simpler Private Sub Workbook_Open() Sheets("Sheet1").Range("E3:M3").EntireColumn.Hidde n = Not .Range("C4").Value End Sub -- HTH RP (remove nothere from the email address if mailing direct) "William" wrote in message ... Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") .Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ .Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#8
|
|||
|
|||
LOL. I took that With out at the last moment and pre-prended the first Range
with it. Bob "William" wrote in message ... Very nice Bob! For the benefit of the OP, I think you intended.... With Sheets("Sheet1") .Range("E3:M3").EntireColumn.Hidden = Not .Range("C4").Value End With Note: C4 must contain either TRUE or FLASE (or be blank). -- ----- XL2003 Regards William "Bob Phillips" wrote in message ... simpler Private Sub Workbook_Open() Sheets("Sheet1").Range("E3:M3").EntireColumn.Hidde n = Not .Range("C4").Value End Sub -- HTH RP (remove nothere from the email address if mailing direct) "William" wrote in message ... Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") .Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ .Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#9
|
|||
|
|||
Thank William but I can't get it to work. I have placed this code in Module 1
of the workbook Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub Saved the file closed and opening it but all the columns are still showing "William" wrote: Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#10
|
|||
|
|||
Pennington
Place the code in the "ThisWorkbook" module, NOT a general module. ----- XL2003 Regards William "Pennington" wrote in message ... Thank William but I can't get it to work. I have placed this code in Module 1 of the workbook Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub Saved the file closed and opening it but all the columns are still showing "William" wrote: Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#11
|
|||
|
|||
Williiam
This code now works on opening the workbook. Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub But what I need is for the columns to be hidden when the value in cell C4 is FALSE and when the value in C4 is changed to TRUE, the columns are revealed with the workbook open. I have tried selecting the command SheetChange instead of Open but it doesn not work - what other options are there. "William" wrote: Pennington Place the code in the "ThisWorkbook" module, NOT a general module. ----- XL2003 Regards William "Pennington" wrote in message ... Thank William but I can't get it to work. I have placed this code in Module 1 of the workbook Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub Saved the file closed and opening it but all the columns are still showing "William" wrote: Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#12
|
|||
|
|||
Place this code in the "ProcessA" worksheet module.
Private Sub Worksheet_Change(ByVal Target As Range) With Sheets("ProcessA") If Not Target(1).Address = .Range("C4").Address Then Exit Sub ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub The code assumes that C4 is not a formula and can only be changed by selecting cell C4. -- ----- XL2003 Regards William "Pennington" wrote in message ... Williiam This code now works on opening the workbook. Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub But what I need is for the columns to be hidden when the value in cell C4 is FALSE and when the value in C4 is changed to TRUE, the columns are revealed with the workbook open. I have tried selecting the command SheetChange instead of Open but it doesn not work - what other options are there. "William" wrote: Pennington Place the code in the "ThisWorkbook" module, NOT a general module. ----- XL2003 Regards William "Pennington" wrote in message ... Thank William but I can't get it to work. I have placed this code in Module 1 of the workbook Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub Saved the file closed and opening it but all the columns are still showing "William" wrote: Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#13
|
|||
|
|||
William
I have now got it to work using the sheetcalculate command and have decided to hide rows rather than columns but I have got another problem. The True and False values are produced from check boxes but when the rows are hidden the check boxes are not - they all move down onto the unhidden rows. How can I hide the check boxes or is there another way of selecting a value by the click of a mouse? "William" wrote: Pennington Place the code in the "ThisWorkbook" module, NOT a general module. ----- XL2003 Regards William "Pennington" wrote in message ... Thank William but I can't get it to work. I have placed this code in Module 1 of the workbook Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub Saved the file closed and opening it but all the columns are still showing "William" wrote: Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
#14
|
|||
|
|||
Pennington
Firstly, dont use the "Calculate" event, use the "Change" event to execute your code. In answer to your post, select all the checkboxes that you want to be hidden / visible when you execute your code to hide / unhide rows and give a name to that selection of checkboxes - In my example I have used "cbgroup". Private Sub Worksheet_Change(ByVal Target As Range) With Sheets("ProcessA") If Not Target(1).Address = .Range("C4").Address Then Exit Sub ..Range("C7:M19").EntireRow.Hidden = False ..Shapes("cbgroup").Visible = True If .Range("C4").Value = False Then ..Range("C7:M19").EntireRow.Hidden = True ..Shapes("cbgroup").Visible = False End If End With End Sub -- ----- XL2003 Regards William "Pennington" wrote in message ... William I have now got it to work using the sheetcalculate command and have decided to hide rows rather than columns but I have got another problem. The True and False values are produced from check boxes but when the rows are hidden the check boxes are not - they all move down onto the unhidden rows. How can I hide the check boxes or is there another way of selecting a value by the click of a mouse? "William" wrote: Pennington Place the code in the "ThisWorkbook" module, NOT a general module. ----- XL2003 Regards William "Pennington" wrote in message ... Thank William but I can't get it to work. I have placed this code in Module 1 of the workbook Private Sub Workbook_Open() With Sheets("ProcessA") Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ Range("E3:M3").EntireColumn.Hidden = True End With End Sub Saved the file closed and opening it but all the columns are still showing "William" wrote: Hi.. Private Sub Workbook_Open() With Sheets("Sheet1") ..Range("E3:M3").EntireColumn.Hidden = False If .Range("C4").Value = False Then _ ..Range("E3:M3").EntireColumn.Hidden = True End With End Sub ----- XL2003 Regards William "Pennington" wrote in message ... I am trying to hide a range of cells when the value in another cell is FALSE and show the range of cells when the value is TRUE. My code is as follows but it doesn't work Private Sub Workbook_Open() If Range("C4").Value = False Then Range("E4:M40").Hide = True End If If Range("C4").Value = True Then Range("E4:M40").Unhide = False End Sub How do I make this work? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
sum of a cell if 2 cells meet a condition | Excel Worksheet Functions | |||
Heps to design Locked/Unlocked cells in protected worksheet | Excel Discussion (Misc queries) | |||
Hiding Formula in cells | Excel Discussion (Misc queries) | |||
How to add cells wiht the condition of the former cell. | Excel Discussion (Misc queries) | |||
condition format for surrounding cells | Excel Discussion (Misc queries) |