using Range(myString)

JohanD

New Member
Joined
Apr 22, 2011
Messages
6
Hello,

I've been trying to make a fast way to hide Rows in a sheet. solutions I found were slowing down the app tremendous when applying a EntireRow.Hidden after each check as seen below.

Code:
While Len(Range("A" & CStr(r)).Value) <> 0
                   
        If Range("N" & CStr(r)).Value <> "d" Then
            Rows(CStr(r) & ":" & CStr(r)).Select
            Selection.EntireRow.Hidden = True
        End If
Wend

but in a sheet for over 500 records. I can make Cofee twice after I applied my filter.
and each time I get an error when I use Range(myRows).Select

Code:
Dim myRows As String
While Len(Range("A" & CStr(r)).Value) <> 0
                   
        If Range("N" & CStr(r)).Value <> "d" Then
            myRows = myRows & r & ":" & r & ","
        End If
                
        r = r + 1
        'remove last comma from the string when we're at the end of the sheet.
        If Len(Range("A" & CStr(r)).Value) = 0 Then
            myRows = Left(myRows, Len(myRows) - 1)
        End If
    Wend
    
#  Range(myRows).Select ##### Error
    Selection.EntireRow.Hidden = True

note that I don't want to use the Sort method for this one as I'm already Sorting the records based on Dates in other parts of the sheet.
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
.Select is slow and can be ditched. You probably want to turn off ScreenUpdating as well, as all the repaints kill time.
 
Upvote 0
Would this achieve the goal?
Code:
Columns("N").AutoFilter Field:=1, Criteria1:="=d"
 
Upvote 0
.Select is slow and can be ditched. You probably want to turn off ScreenUpdating as well, as all the repaints kill time.

OMG That's simple

i've added
Code:
Application.ScreenUpdating = False
on top of the Sub


and the .Select changed to

Code:
Rows(CStr(r) & ":" & CStr(r)).EntireRow.Hidden = True
 
Upvote 0
Would this achieve the goal?
Code:
Columns("N").AutoFilter Field:=1, Criteria1:="=d"

.Autofilter lets me only use 1 field to sort on Right?

my example wasn't realy complete to show what I'm doing but I'm hiding Rows where more conditions happen in several columns.
 
Upvote 0
.Autofilter lets me only use 1 field to sort on Right?

my example wasn't realy complete to show what I'm doing but I'm hiding Rows where more conditions happen in several columns.
I thought we were hiding rows/filtering, not sorting.

Autofilter can be applied to one or many columns. Whether it would suit your purpose depends on just what that purpose is. If AutoFilter was applicable, it would most probably be much simpler/quicker than cycling through every row ofr your relevant columns. More details would be required to assess if AutoFilter could be used effectively for you.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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