Simplifying VBA

bptaw

Board Regular
Joined
Feb 27, 2017
Messages
69
Office Version
  1. 2016
Platform
  1. Windows
I am trying to understand VBA better and want help to simplify the following VBA I use to hide and reveal rows and columns. A sample is shown below:
Case Is = "Fibre": Rows("40:45").EntireRow.Hidden = True
Rows("46:52").EntireRow.Hidden = False
Sheets("Summary Page").Columns("B:D").EntireColumn.Hidden = False
Sheets("Summary Page").Columns("K:L").EntireColumn.Hidden = False
Sheets("Summary Page").Columns("E:J").EntireColumn.Hidden = True
Sheets("Summary Page").Columns("M:S").EntireColumn.Hidden = True
Sheets("Summary Page").Rows("2,4").EntireRow.Hidden = True
Sheets("Summary Page").Rows("4").EntireRow.Hidden = True
Sheets("Summary Page").Rows("3").EntireRow.Hidden = False

Any help appreciated
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You can group certain statements together, which I guess is simplifying your code a bit, such as:
VBA Code:
With Worksheets("Summary Page")
    .Range("B:D,K:L").EntireColumn.Hidden = False
    .Range("E:J,M:S").EntireColumn.Hidden = True
    .Rows("2:4").EntireRow.Hidden = True
    .Rows(3).Hidden = False
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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