Macro Show/Hinding Rows/Columns slowing down Entire sheet

switzer35

New Member
Joined
Feb 6, 2008
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a Macro that is working to Show/Hide specific rows or columns based on a "Y"/"N" placed in a specific cell. Everything is working however, it is slowing down the entire sheet when I move from cell to cell there is a slight delay. Is there a better way to write this code so that it does not create this delay throughout the whole worksheet?

Code:
''Show/Hide Unit Labor Line Item Pricing for BOM With Out Unit Pricing
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = Fales

If Range("J3").Value = "N" Then
Rows("9").EntireRow.Hidden = True

ElseIf Range("J3").Value = "Y" Then
Rows("9").EntireRow.Hidden = False

End If

If Range("J5").Value = "N" Then
Rows("11").EntireRow.Hidden = True

ElseIf Range("J5").Value = "Y" Then
Rows("11").EntireRow.Hidden = False

End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
636
Office Version
  1. 365
Platform
  1. Windows
Try this instead.
It requires manually changes in J3 or in J5 to run.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$3" Then
  Rows("9").EntireRow.Hidden = Target.Value = "N"
ElseIf Target.Address = "$J$5" Then
  Rows("11").EntireRow.Hidden = Target.Value = "N"
End If
End Sub
 
Solution

switzer35

New Member
Joined
Feb 6, 2008
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Try this instead.
It requires manually changes in J3 or in J5 to run.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$3" Then
  Rows("9").EntireRow.Hidden = Target.Value = "N"
ElseIf Target.Address = "$J$5" Then
  Rows("11").EntireRow.Hidden = Target.Value = "N"
End If
End Sub

Yes this is much faster and doesn't cause the delays on the whole sheet. Thanks for the quick response and your help!
 

Watch MrExcel Video

Forum statistics

Threads
1,130,172
Messages
5,640,583
Members
417,152
Latest member
DayTimeSeby

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
Top