Routine for the cursor and scroll position and also hide the blank rows.

beloshi

New Member
Joined
Jul 5, 2018
Messages
29
Hi Excel Gurus,

Once again I am very much thankful to this community due to which I learned a lot. I am stuck in the current routine although it is not giving any error and executing but its not hiding the rows as mentioned which are blank has no data. To be more precise I have selected the sheets for which I want to apply the hidden routine to.

Kindly help

Code I am using is below for reference ;

Code:
Sub Position()
Dim iLastRow As Integer
Dim ws As Worksheet


On Error Resume Next
For Each ws In Worksheets
    Application.Goto Reference:=ws.Range("A1"), Scroll:=True
    
    'Hide blank rows
    If ws.Name = "DQ % Stores " Or ws.Name = "DQ # Stores" Or ws.Name = "DQ % New Reg Stores" _
    Or ws.Name = "DQ # New Reg Stores" Or ws.Name = "DQ % Stores per Branch" _
    Or ws.Name = "DQ # Stores per Branch" Or ws.Name = "DQ % Stores Branch New Reg" _
    Or ws.Name = "DQ # Stores Branch New Reg" Then
    
        iLastRow = ws.Cells(129, 2).End(xlUp).Row
        For i = iLastRow + 1 To 129
            ws.Rows(i).Hidden
        Next
    End If
Next
On Error GoTo 0
End Sub

best regards

Beloshi
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
remove this line & see what happens
Code:
On Error Resume Next
 
Upvote 0
I hardly ever use:
OnError Resume next

What your telling Excel is to ignore all the errors in my code and just keep going.
This can be used when you know a error will occur but you know why the error occurred and still want to ignore it because you know why it occurred.

The reason your not getting a error code is because you told Excel you do not want to be told when a Error occurs.
 
Upvote 0
If you want to hide those rows use
Code:
ws.Rows(i).Hidden=True
Otherwise change True to False
 
Upvote 0
If you want to hide those rows use
Code:
ws.Rows(i).Hidden=True
Otherwise change True to False


It worked like a charm. How can I forget this. Thanks alot Fluff.

Here is the complete code if someone in future get stuck in something like this.

Code:
Sub Position()
Dim iLastRow As Integer
Dim ws As Worksheet


'On Error Resume Next
For Each ws In Worksheets
    Application.Goto Reference:=ws.Range("A1"), Scroll:=True
    
    'Hide blank rows
    If ws.Name = "A" Or ws.Name = "B" Or ws.Name = "C" _
    Or ws.Name = "D" Or ws.Name = "E" _
    Or ws.Name = "F" Or ws.Name = "G" _
    Or ws.Name = "H" Then
    
        iLastRow = ws.Cells(129, 2).End(xlUp).Row
        For i = iLastRow + 1 To 129
            ws.Rows(i).Hidden = True
        Next
    End If
Next
On Error GoTo 0
End Sub
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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