VBA - Combining IF and Hidden rows

Jnrrpg11

New Member
Joined
Jun 29, 2017
Messages
28
Hello Everyone,

Ive built a Spreadsheet which will reveal some rows (which contain notes) once a button is pressed.
It will then hide the rows once another row is pressed. Below is a simplified version of the sheet.



So once we press the 'Show Notes' button above it will run the simple macro 'Reveal_Item_1' below.



This will take the Rows 4, 5 & 6 and "unhide" them revealing the notes.



As you see on Row 4, it reveals a new button in Cell D4 which is linked to the Macro 'Hide_Item_1' which simply changes the 'Hidden = False' to a 'Hidden = True'

So heres the Question - Is there a way of linking them to the same button and including both commands under the same macro... a 'Show/Hide Notes' using an IF statement.
I was thinking something along the lines of -

Sub HideReveal_item_1
IF Row 4 = Hidden
Then Rows("4:6").EntireRow.Hidden = False
Else:
Rows("4:6").EntireRow.Hidden = True

This code will not work at all cause its missing some bits but does anyone know what you would add to make this code work.

Thanks in Advance
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this:
Code:
Sub HideReveal_item_1()

If Rows("4").Hidden = True Then
    Rows("4:6").EntireRow.Hidden = False
Else
    Rows("4:6").EntireRow.Hidden = True
End If

End Sub
 
Upvote 0
Hey Joe,

Thanks for the reply, the code works perfectly.
I look at it a it makes total sense but I just needed that extra bit.

Thanks again for your help.
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top