ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to set row color (https://www.excelbanter.com/excel-programming/372849-how-set-row-color.html)

hon123456

How to set row color
 
Dear all,

I have code as follows:

k = 0
For i = 0 To rs.RecordCount - 1
k = k + 2
For j = 0 To rs.Fields.Count - 1

Sheet1.Cells(k + 5, j + 1) = rs.Fields(j).Value
' How to add code to change the row of k+5

Next j

rs.movenext
next i

In the above code, I want to change the row color of rows
k+5 to green. How can I do that?

Thanks


JLGWhiz

How to set row color
 
This will paint it green but you will have to add in the conditions you want
to exist.
e.g. If... Then

Worksheets(2).Cells(k + 5, j + 1).EntireRow.Interior.ColorIndex = 4

End If

"hon123456" wrote:

Dear all,

I have code as follows:

k = 0
For i = 0 To rs.RecordCount - 1
k = k + 2
For j = 0 To rs.Fields.Count - 1

Sheet1.Cells(k + 5, j + 1) = rs.Fields(j).Value
' How to add code to change the row of k+5

Next j

rs.movenext
next i

In the above code, I want to change the row color of rows
k+5 to green. How can I do that?

Thanks



JLGWhiz

How to set row color
 
Be careful putting that code in a For...Next loop. You could paint every
line that meet your For selection criteria. If this is what you want then
forget the If ... then statement and just use the command line.

"JLGWhiz" wrote:

This will paint it green but you will have to add in the conditions you want
to exist.
e.g. If... Then

Worksheets(2).Cells(k + 5, j + 1).EntireRow.Interior.ColorIndex = 4

End If

"hon123456" wrote:

Dear all,

I have code as follows:

k = 0
For i = 0 To rs.RecordCount - 1
k = k + 2
For j = 0 To rs.Fields.Count - 1

Sheet1.Cells(k + 5, j + 1) = rs.Fields(j).Value
' How to add code to change the row of k+5

Next j

rs.movenext
next i

In the above code, I want to change the row color of rows
k+5 to green. How can I do that?

Thanks




All times are GMT +1. The time now is 08:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com