Workaround For Limit To Working With Noncontiguous Visible Cells

Wookiee

Active Member
Joined
Nov 27, 2012
Messages
429
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have created a macro for some co-workers to use which helps them clean up and format some daily reports which originate from text files. They still have to import the files from the raw text file by manually setting delimiters and removing superfluous columns, but once they get it open in Excel, my macro has enabled them to save about 15 minutes per day by automating the cleanup of the files. These files usually have thousands of rows and it's not possible to determine how many will appear each day.

Since I created the macro, the large number of rows hasn't presented a problem, but today there were about 90K rows and my macro kept throwing errors due to the fact that I use a method of filtering, then deleting or updating visible cells based on the filter criteria. I modified my code to try and handle these situations, but VBA seems to stop no matter what I do whenever I attempt to use SpecialCells(xlCellTypeVisible) on a range of more than 8,192 noncontiguous rows.

I've attempted a number of permutations of the codes below, but have as of yet been unable to devise a workaround that works.

Code:
Private Sub Delete_Noncontiguous_Visible_Cells()

On Error GoTo TheHardWay
Selection.SpecialCells(xlCellTypeVisible).EntireColumn.Delete
Exit Sub

TheHardWay:
For Each rngCell In Selection.SpecialCells(xlCellTypeVisible)
    rngCell.EntireColumn.Delete
Next rngCell

End Sub
Code:
Private Sub Noncontiguous_1s()

On Error GoTo TheHardWay
Selection.SpecialCells(xlCellTypeVisible) = "1"
Exit Sub

TheHardWay:
For Each rngCell In Selection.SpecialCells(xlCellTypeVisible)
    rngCell = "1"
Next rngCell

End Sub

PS. I know that I could sort the rows so that my filter criteria chooses a range of contiguous rows, but the data needs to be preserved in the sequence it appears in the original text file. I also imagine a looped structure could probably work, but I'd prefer to avoid that option if possible.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
:oops: Wookiee - my apologies for steering you down the wrong path. Maybe, though, you found/learned something you can use now or later!
 
Upvote 0
No apologies necessary, Rallcorn. I appreciate all your assistance and advice and I believe that this thread will probably benefit me in the future at some point.

And since I had actually come up with a workable solution before I even attempted to play around with Rick's macro, this was a chance for me to explore some different methodology.

Cheers!
(y)
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,026
Members
449,061
Latest member
TheRealJoaquin

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