Using Vbscript for an Excel 2010 worksheet, how can I find the start and 
end range of distinct values with a column ? 

I have a worksheet with some 200k rows, and 45 columns. 20 of such columns 
contain rows indicating a color value that I need to set. I have code that 
works but when working on 200k rows it is incredibly slow. 

Set objRange = objXLWs.UsedRange 
iRows = objRange.Rows.Count 
iColumns = objRange.Columns.Count 

                     For iR = 2 To iRows 
                 Select Case objRange.Item(iR, iC).Value 
                    Case "Y" 
                   objXLApp.Range(objRange.Item(
iR, iC-1),objRange.Item(iR, iC-1)).Interior.ColorIndex = 6 'yellow 
                    Case "R" 
                   objXLApp.Range(objRange.Item(iR, iC-1),objRange.Item(iR, 
iC-1)).Interior.ColorIndex = 3 'red 
                    Case "O" 
                   objXLApp.Range(objRange.Item(iR, iC-1),objRange.Item(iR, 
iC-1)).Interior.ColorIndex = 45 'orange 
                    Case "T" 
                   objXLApp.Range(objRange.Item(iR, iC-1),objRange.Item(iR, 
iC-1)).Interior.ColorIndex = 42 'terquoise 
                    End Select 
                     Next 

What I am thinking is that sorting the column, bringing all the color 
values to the top, then finding the distinct ranges of each of the 4 x 
color values and trying to color by a range rather than individual row case 
statement. Sadly I have no idea how to do so. Obviously I would then resort 
by the original file format following all columns having been colored. 

Can anyone please give me some example code on how I would do this ? I have 
sort code that seems to work, I just cannot figure how to get start and end 
cell addresses for a block color statement. 

Set objRange2 = objXLWs.Cells(2, iC) 
objXLWs.UsedRange.Sort objRange2, xlAscending, , , , , , xlYes 

Many thanks for any help, Fin. 

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to