Hi all,
I'll be the first to admit I'm quite new to VBA, but delving into it as much as I can.
I've been building a questionnaire & want to be able to hide certain rows based on a certain value of a cell.
I have managed this successfully on one sheet within my workbook, however when I copy and paste the code across to another sheet module, in exactly the same format and requesting the exact same function it does not work.
This is the code I have used once already on the sheet which worked;
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E4").Value = False Then
Rows("5:6").EntireRow.Hidden = True
ElseIf Range("E4").Value = True Then
Rows("5:6").EntireRow.Hidden = False
End If
End Sub
I think it makes a difference that I'm using a 'Check box (form control)' from the developer insert menu as an easier way to toggle the value of the cell in E4.
When replicating it in the next sheet, I'm using the same code but just changing the cell to lookup the value & the rows to hide- but it does not want to work.
As a test in the new sheet, I changed the value look up cell to a cell which wasn't linked to the checkbox macro (eg, changing E4 to F4) with the rows that I'm wanting to hide staying the same. I then physically typed in FALSE and TRUE into this cell and it hid the rows that I requested.
My question are...
why does it all of a sudden not like to work on my second sheet as it did on my first?
why does it work if I change the cell lookup to a different cell and physically type in False / True, but it doesn't toggle when I use the macro?
Thanks in Advance!
I'll be the first to admit I'm quite new to VBA, but delving into it as much as I can.
I've been building a questionnaire & want to be able to hide certain rows based on a certain value of a cell.
I have managed this successfully on one sheet within my workbook, however when I copy and paste the code across to another sheet module, in exactly the same format and requesting the exact same function it does not work.
This is the code I have used once already on the sheet which worked;
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E4").Value = False Then
Rows("5:6").EntireRow.Hidden = True
ElseIf Range("E4").Value = True Then
Rows("5:6").EntireRow.Hidden = False
End If
End Sub
I think it makes a difference that I'm using a 'Check box (form control)' from the developer insert menu as an easier way to toggle the value of the cell in E4.
When replicating it in the next sheet, I'm using the same code but just changing the cell to lookup the value & the rows to hide- but it does not want to work.
As a test in the new sheet, I changed the value look up cell to a cell which wasn't linked to the checkbox macro (eg, changing E4 to F4) with the rows that I'm wanting to hide staying the same. I then physically typed in FALSE and TRUE into this cell and it hid the rows that I requested.
My question are...
why does it all of a sudden not like to work on my second sheet as it did on my first?
why does it work if I change the cell lookup to a different cell and physically type in False / True, but it doesn't toggle when I use the macro?
Thanks in Advance!