Is there a way to improve this code ?

krasibsbg

New Member
Joined
Feb 12, 2015
Messages
19
Merry Christmas to all!
Is there a way to improve this code?

Code:
 [B]Private Sub Worksheet_Change(ByVal Target As Range)[/B]
[B]Dim MyCells As Range[/B]
 
[B]Set MyCells = Range("B8:B16")[/B]
 
[B]If Not Intersect(Target, MyCells) Is Nothing Then[/B]
 
[B]Application.EnableEvents = False[/B]
[B]Application.ScreenUpdating = False[/B]
[B]Application.Calculation = xlCalculationManual[/B]
 
[B]Sheets(1).Range("7:26").EntireRow.Hidden = False[/B]
[B]Sheets(2).Range("7:36").EntireRow.Hidden = False[/B]
[B]If Range("B7").Value = "" Then[/B]
[B]Sheets(1).Range("7:8").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("7:9").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B8").Value = "" Then[/B]
[B]Sheets(1).Range("9:10").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("10:12").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B9").Value = "" Then[/B]
[B]Sheets(1).Range("11:12").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("13:15").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B10").Value = "" Then[/B]
[B]Sheets(1).Range("13:14").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("16:18").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B11").Value = "" Then[/B]
[B]Sheets(1).Range("15:16").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("19:21").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B12").Value = "" Then[/B]
[B]Sheets(1).Range("17:18").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("22:24").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B13").Value = "" Then[/B]
[B]Sheets(1).Range("19:20").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("25:27").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B14").Value = "" Then[/B]
[B]Sheets(1).Range("21:22").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("28:30").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B15").Value = "" Then[/B]
[B]Sheets(1).Range("23:24").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("31:33").EntireRow.Hidden = True[/B]
[B]End If[/B]
[B]If Range("B16").Value = "" Then[/B]
[B]Sheets(1).Range("25:26").EntireRow.Hidden = True[/B]
[B]Sheets(2).Range("34:36").EntireRow.Hidden = True[/B]
[B]End If[/B]
 
[B]Application.EnableEvents = True[/B]
[B]Application.ScreenUpdating = True[/B]
[B]Application.Calculation = xlCalculationAutomatic[/B]
 
[B]End If[/B]
 
[B]End Sub[/B]


Thank you in advance for help /bow/
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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