Vba

gr33nh07n

New Member
Joined
Jun 28, 2016
Messages
2
Hi, I'm quite poor on excel and have been trying to research and learn the answer myself but I cannot.

My code below is trying to hide a row when the answer above is answered YES and unhide when the answer is NO. I can get the code to work for one row but cannot seem to get the code to run for all 4 rows. Please help me before I smash my new laptop...



Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B9").Value = "Yes" Then
Rows("10:10").EntireRow.Hidden = True
ElseIf Range("B9").Value = "No" Then
Rows("10:10").EntireRow.Hidden = False
If Range("B12").Value = "Yes" Then
Rows("13:13").EntireRow.Hidden = True
ElseIf Range("B12").Value = "No" Then
Rows("13:13").EntireRow.Hidden = False
If Range("B14").Value = "Yes" Then
Rows("15:15").EntireRow.Hidden = True
ElseIf Range("B14").Value = "No" Then
Rows("15:15").EntireRow.Hidden = False
If Range("B18").Value = "Yes" Then
Rows("19:19").EntireRow.Hidden = True
ElseIf Range("B18").Value = "No" Then
Rows("19:19").EntireRow.Hidden = False
End If
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
See if using this code instead of what you posted does what you want...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Rows(10).Hidden = Range("B9").Value = "Yes"
  Rows(13).Hidden = Range("B12").Value = "Yes"
  Rows(15).Hidden = Range("B14").Value = "Yes"
  Rows(19).Hidden = Range("B18").Value = "Yes"
End Sub
 
Upvote 0
See if using this code instead of what you posted does what you want...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Rows(10).Hidden = Range("B9").Value = "Yes"
  Rows(13).Hidden = Range("B12").Value = "Yes"
  Rows(15).Hidden = Range("B14").Value = "Yes"
  Rows(19).Hidden = Range("B18").Value = "Yes"
End Sub

That works a treat, thank you so much
 
Upvote 0

Forum statistics

Threads
1,217,044
Messages
6,134,202
Members
449,862
Latest member
Muhamad Irfandi

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