VBA hide rows takes long

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
365
Hi, I was wondering if the code below can be improved to be more efficient. It takes a long time and sometimes locks up the file. Thanks

VBA Code:
Sub HIDE_ROWS()
Application.ScreenUpdating = False
    BeginRow = 5
    EndRow = 700
    ChkCol = 4

    For RowCnt = BeginRow To EndRow
            If Cells(RowCnt, ChkCol).Value = "" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt
    Range("c:c").EntireColumn.Hidden = True
    Application.ScreenUpdating = True
End Sub
 
The Desired result should be the following pic ...

No blanks in column 4 aka the D column.
 

Attachments

  • Desired.PNG
    Desired.PNG
    4.8 KB · Views: 8
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
the cells in column D will not have any formulas or data, only what I input into the cell. As far as the number of lines, I used 700 just to cover myself, but I guess it would be better not to have to worry about revising the code if I exceeded that at some point. I see there was a comment about starting from the bottom and working up? Right now I am using the code from post #2 which is working well. Thanks
 
Upvote 0
I enclosed a photo to show the original file and a photo to show the results from your suggestion.
When did the OP show us that original file? Also, when did the OP say there were duplicates values that had to be "collapsed" into a single cell with counts showing?
 
Upvote 0
When did the OP show us that original file? Also, when did the OP say there were duplicates values that had to be "collapsed" into a single cell with counts showing?
my apologies @Rick Rothstein for any confusion I have caused. The OP didn't provide a file, The pics I provided were the results of a previous file I had worked on, the alleged 'original' file, and was applying the code from this thread. It was merely to demonstrate the results to column 4 and the C column. Again, my apologies for any confusion.
 
Upvote 0
Is below the best way to un-hide the rows and columns? Thanks

VBA Code:
Sub UNHIDE_ROWS()
Cells.EntireRow.Hidden = False
Cells.EntireColumn.Hidden = False
End Sub
 
Upvote 0
Not sure if it is better, but it is shorter...
VBA Code:
Rows.Hidden = False
Columns.Hidden = False
 
Upvote 0
If the cells in the ChkCol columns contain formulas that return numbers (dates included) or the empty text string (""), then we can still use SpecialCells to find the "blanks"...
VBA Code:
Range(Cells(BeginRow,ChkCol),Cells(EndRow,ChkCol)).SpecialCells(xlFormulas, xlTextValues).EntireRow.Hidden = True
Hi Rick,
it just so happens that I needed to use my code in another program to hide rows that were NOT truly blank and had formulas in them. So I used your above line which worked fine - so thanks for thinking of that possibility.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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