View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default PrintTitleRows 2

I think this is what you want?...
'--
Sub TopStuff()
' always use a Long for a row number
Dim i As Long
Dim rngTop As Range
i = 1
' specify the starting point.
Range("A1").Select

Do Until Selection.Interior.ColorIndex < -4142
ActiveCell.Offset(1, 0).Select
i = 1 + i
Loop
Set rngTop = Range("A1", Cells(i, 1))
MsgBox rngTop.Address
End Sub
'--
'In general, selecting cells is not good practice.
'However, in place of the last two lines you could use...
Range("A1", Cells(i, 1)).Select
MsgBox Selection.Address
--
Also, there is more than one way to code the above.
If the first colored cell was at row 25000,
then code execution might take longer than you want.
'--
'Further, you can only make a selection on the active sheet.
'That is why you should select a sheet first,then make a selection.
'In your case everything takes place on the active sheet, so
'no sheet selection is necessary.
'--
Jim Cone
Portland, Oregon USA



"SteveDB1"

wrote in message
Good morning Jim.
Thank you for the response yesterday evening.

At this point, I've got a do until loop that iterates through all of the
first few rows that are not filled with an interior color. When it finds a
row that is ...interior.colorindex <-4142 it stops.
My next goal is to select the range from the start row, to the last row in
my loop-- the i-th row--so that I can perform the task of selecting those
rows, then fulfill a subsequent task.

It's the selection of those rows that's stumping me.
Yesterday afternoon after I'd posted this, I finally found the code to make
a selection, but it either selected the i-th row, downward to the 17th row
below the i-th row, or skipped some rows and then selected i- number of rows.
I know that it's something simple, but so far I haven't found it.
My existing code so far is:
----------------------------------
Dim i As Integer
i = 1
Do Until Selection.Interior.ColorIndex < -4142
ActiveCell.Offset(1, 0).Select
i = 1 + i
Loop

If Selection.Interior.ColorIndex < -4142 Then
'everything works until here.
'this next function does not work.
ActiveSheet.Select 'I chose this because the help file said I had to.
Selection.range("a1", Row.cell(i)).Select

End If
---------------------------------

for whatever reason, instead of selecting cell a1, it treats the i-th row as
a1, and then dropped down 17 more rows, and selected all of them.
I specifically am seeking to select row 1, and then include row 1 to the
i-th row.
I hope that makes my thinking clearer. If not, please let me know, and I'll
try further to clarify.
Again, I really appreciate your time and assistance.