Use formula to define "Const" value when hidding rows

alecwarner

New Member
Joined
Aug 9, 2013
Messages
16
Hi

I use the code below in several places to "hide" rows that have no data. I'm trying to speed up the code by reducing the range of rows.

Is it possible to define the "end_row2" constant by a formula instead of a fixed number 118?

I tried already:

Const end_row2 As Long = Sheet16.Range("$L$78").Value

But this just alarms out????????

Any help would be appreciated.


VBA Code:
Const start_row2 As Long = 79
Const check_col2 As Long = 5
Const end_row2   As Long = 118
    
Dim r2           As Range
Dim x2           As Long
    
Application.ScreenUpdating = False
        
With Sheet16
'     With .Cells(start_row2, 1).Resize(end_row2 - start_row2 + 1).EntireRow
'         .AutoFit
'         .Hidden = False
'     End With
For x2 = start_row2 To end_row2
If Len(.Cells(x2, check_col2).Value) = 0 Or .Cells(x2, check_col2).Value = 0 Then
If not r2 Is Nothing Then
Set r2 = Union(r2, .Cells(x2, check_col2))
Else
Set r2 = .Cells(x2, check_col2)
End If
End If
Next x2
If Not r2 Is Nothing Then
r2.EntireRow.Hidden = True
Set r2 = Nothing
End If
End With
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
A constant is, by definition, constant. You need a variable - eg:

Code:
Dim end_row2 As Long
end_row2 = Sheet16.Range("$L$78").Value

Also, please use code tags when posting code.
 
Upvote 0

Forum statistics

Threads
1,214,824
Messages
6,121,783
Members
449,049
Latest member
greyangel23

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