VBA - How to parcel a large selection to avoid XL Crash

  • Thread starter donoteventry;removes;pam
  • Start date
D

donoteventry;removes;pam

2003

VBA code that I use works fine except for large files.

Part of the code, selects all formula cells then applies a border around a sub-set of those cells
limited by the application of a IF statement as follows:

Set MyRange = Selection.SpecialCells(xlFormulas, 23)
If Not IsError(MyRange.DirectPrecedents) Then
With MyRange.DirectPrecedents
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeLeft).ColorIndex = 4 ' Bright Green
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeTop).ColorIndex = 4 ' Bright Green
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeBottom).ColorIndex = 4 ' Bright Green
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeRight).ColorIndex = 4 ' Bright Green
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideVertical).Weight = xlMedium
.Borders(xlInsideVertical).ColorIndex = 4 ' Bright Green
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).Weight = xlMedium
.Borders(xlInsideHorizontal).ColorIndex = 4 ' Bright Green
End With

A problem occurs with large files where either the shear number of selected cells overwhelms Excel
and/or the processing involved in applying the borders to those causes Excel to crash.

My question, with VBA, how can I programmatically limit the number of cells (it might be that 8192
non-contiguous cell issue) to say groups of say 5000 cells per processing loop but at the same time
make sure that of all the desire cells are processed?

Thanks

EagleOne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Micro to do borders question. 3
Border formatting row of cells 22
help needed with borders 2
Do I need these lines? 5
Cell Border 1
with, end with format 2
Help with macro 1
Loops through Sheets but doesn't work. 5

Top