Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Format row based on value

Hello,

I have this code that look at the values in column 2 for each row specified
in the code (2 to 9216). I want it to colour the row everytime the value
changes. This does this perfectly except it doesnt colour the row then the
value first changes. So for example if row 2 to 6 are the same and row 7 to
10 are the same, rows 8 to 10 are formatted.

Can anyone help with this?

Dim lRow As Long
Dim lCol As Long

For lRow = 2 To 9216

If Cells(lRow, 2).Value = Cells(lRow - 1, 2) Then
If IsEmpty(Cells(lRow, 256)) Then
lCol = Cells(lRow, 256).End(xlToLeft).Column
Else
lCol = 256
End If
Range(Cells(lRow, 1), Cells(lRow, lCol)).Interior.ColorIndex = 36
End If
Next

This is a repost from earlier today, I hope I have worded it better!

Martin
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Format row based on value

Hi,

Thanks, I see what you mean however the formatting needs to take place over
10,000 lines and row 2 will have no relevance to say row 1,500.

What I need is to say by code for example is if current IRow, column 2 is
different to the row above, column 2 then do the formatting

"Nigel" wrote:

A quick fix - change the first If statement as follows.....

If Cells(lRow, 2).Value = Cells(lRow - 1, 2) Or lRow = 2 Then


--

Regards,
Nigel




"Martin" wrote in message
...
Hello,

I have this code that look at the values in column 2 for each row
specified
in the code (2 to 9216). I want it to colour the row everytime the value
changes. This does this perfectly except it doesnt colour the row then
the
value first changes. So for example if row 2 to 6 are the same and row 7
to
10 are the same, rows 8 to 10 are formatted.

Can anyone help with this?

Dim lRow As Long
Dim lCol As Long

For lRow = 2 To 9216

If Cells(lRow, 2).Value = Cells(lRow - 1, 2) Then
If IsEmpty(Cells(lRow, 256)) Then
lCol = Cells(lRow, 256).End(xlToLeft).Column
Else
lCol = 256
End If
Range(Cells(lRow, 1), Cells(lRow, lCol)).Interior.ColorIndex = 36
End If
Next

This is a repost from earlier today, I hope I have worded it better!

Martin



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Format row based on value

You need to explain what you are trying to achieve? As I see it coloring
the first row of each group will color all rows! Or do you have blank rows
you do not wish to color?



--

Regards,
Nigel




"Martin" wrote in message
...
Hi,

Thanks, I see what you mean however the formatting needs to take place
over
10,000 lines and row 2 will have no relevance to say row 1,500.

What I need is to say by code for example is if current IRow, column 2 is
different to the row above, column 2 then do the formatting

"Nigel" wrote:

A quick fix - change the first If statement as follows.....

If Cells(lRow, 2).Value = Cells(lRow - 1, 2) Or lRow = 2 Then


--

Regards,
Nigel




"Martin" wrote in message
...
Hello,

I have this code that look at the values in column 2 for each row
specified
in the code (2 to 9216). I want it to colour the row everytime the
value
changes. This does this perfectly except it doesnt colour the row then
the
value first changes. So for example if row 2 to 6 are the same and row
7
to
10 are the same, rows 8 to 10 are formatted.

Can anyone help with this?

Dim lRow As Long
Dim lCol As Long

For lRow = 2 To 9216

If Cells(lRow, 2).Value = Cells(lRow - 1, 2) Then
If IsEmpty(Cells(lRow, 256)) Then
lCol = Cells(lRow, 256).End(xlToLeft).Column
Else
lCol = 256
End If
Range(Cells(lRow, 1), Cells(lRow, lCol)).Interior.ColorIndex = 36
End If
Next

This is a repost from earlier today, I hope I have worded it better!

Martin




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Format row based on value

Hi,

Here is a sample of the data I have:

Column Heading
Area 1
Area 1
Area 1
Area 2
Area 2
Area 2
Area 2
Area 3
Area 3
Area 3
Area 3

I want to leave the rows with the value of "Area 1" as normal. If the row
then changes to another name, in this example "Area 2" then format the rows
yellow. If the value changes again, in this example "Area 3" then leave the
rows as normal and so on and so on.

The code I posted below does this almost perfectly but does not colour the
first row when the change takes place i.e. the first row with "Area 2".



"Nigel" wrote:

You need to explain what you are trying to achieve? As I see it coloring
the first row of each group will color all rows! Or do you have blank rows
you do not wish to color?



--

Regards,
Nigel




"Martin" wrote in message
...
Hi,

Thanks, I see what you mean however the formatting needs to take place
over
10,000 lines and row 2 will have no relevance to say row 1,500.

What I need is to say by code for example is if current IRow, column 2 is
different to the row above, column 2 then do the formatting

"Nigel" wrote:

A quick fix - change the first If statement as follows.....

If Cells(lRow, 2).Value = Cells(lRow - 1, 2) Or lRow = 2 Then


--

Regards,
Nigel




"Martin" wrote in message
...
Hello,

I have this code that look at the values in column 2 for each row
specified
in the code (2 to 9216). I want it to colour the row everytime the
value
changes. This does this perfectly except it doesnt colour the row then
the
value first changes. So for example if row 2 to 6 are the same and row
7
to
10 are the same, rows 8 to 10 are formatted.

Can anyone help with this?

Dim lRow As Long
Dim lCol As Long

For lRow = 2 To 9216

If Cells(lRow, 2).Value = Cells(lRow - 1, 2) Then
If IsEmpty(Cells(lRow, 256)) Then
lCol = Cells(lRow, 256).End(xlToLeft).Column
Else
lCol = 256
End If
Range(Cells(lRow, 1), Cells(lRow, lCol)).Interior.ColorIndex = 36
End If
Next

This is a repost from earlier today, I hope I have worded it better!

Martin




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditiona format based on format of another cell Tami Excel Worksheet Functions 1 December 18th 09 04:48 AM
Setting cell format based on format codes Hans Knudsen Excel Programming 3 October 11th 08 07:47 PM
If / Then based off conditional format bill ch Excel Programming 5 March 1st 07 11:23 PM
how do i format a cell based on format of a range of cells? Chris Hardick Excel Discussion (Misc queries) 2 April 3rd 06 08:54 AM
Number format based on number format of another cell in another workbook Rob Excel Programming 9 January 9th 05 04:30 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"