Rewrite the code for quicker action

shaju

Board Regular
Joined
Jul 12, 2004
Messages
80
Office Version
  1. 2010
Platform
  1. Windows
The following code just check for the "zero values" in the specified range, and will hide the "zero valued"row and column.
It is used in the Sheet selection event. Can it be rewritten so that it will run faster
TIA



Sub ShapeIt()

Application.ScreenUpdating = False
Sheet1.Range("B156:IH156").Columns.Hidden = False
Sheet1.Range("B156:IH156").Rows.Hidden = False
Sheet1.Range("B156:IH156").Columns.AutoFit
'On Columns
For Each c In Sheet1.Range("B156:IH156")
If c.Value = 0 Then
c.Columns.Hidden = True
End If
Next c
'On Rows
For Each c In Sheet1.Range("IH5:IH156")
If c.Value = 0 Then
c.Rows.Hidden = True
End If
Next c
Cancel = True
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I
Sheet1.Range("B156:IH156").Columns.Hidden = False
Sheet1.Range("B156:IH156").Rows.Hidden = False
Sheet1.Range("B156:IH156").Columns.AutoFit
'On Columns
For Each c In Sheet1.Range("B156:IH156")

'On Rows
For Each c In Sheet1.Range("IH5:IH156")
Are you only checking one column (IH) and one row (156) for zeros or are your range designations incorrect in the above parts of your code?
 
Upvote 0
I

Are you only checking one column (IH) and one row (156) for zeros or are your range designations incorrect in the above parts of your code?
I am checking values in Only one Column (IH) and One row(156).
Because Formula in IH5 is SUM(B5:IG5), IH6 is SUM(B6:IG6) and so on.
Formula in B156 is Sum(B5:B155),, C156 is Sum(C5:C155) and so on
These two (Col IH and Row 156) are just total of the rows and columns .
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,007
Members
449,203
Latest member
Daymo66

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