Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA to highlight cells

Hi folks,

hope you can help with a little problem. The has to be achieved using
VBA so please don't suggest conditional formatting as it wont achieve
what is required.

we have a sheet in the following format:


A B C D
101 10A "Some String" "Some String"
101 10A "Some String" "Some String"
101 50A "Some String" "Some String"
303 50A "Some String"
303 50A "Some String" "Some String"
303 1152A "Some String" "Some String"


Ok here is the problem... we wish to highlight (color) the background
of each row that has identical vales in column B. The sheet auto
updates from a data source, and is sorted on the values in column B,
therefore all identical values will remain together.

Any help would be appreciated as this is driving me mad.

Many thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VBA to highlight cells

Public Sub ProcessData()
Const TEST_COLUMN As String = "B" '<=== change to suit
Dim i As Long
Dim mpLastRow As Long


With ActiveSheet

For i = 2 To mpLastRow
If Application.CountIf(.Columns(2), .Cells(i,
TEST_COLUMN).Value) 1 Then
.Rows(i).Interior.ColorIndex = 3
End If
Next i

End With

End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Amcdee" wrote in message
oups.com...
Hi folks,

hope you can help with a little problem. The has to be achieved using
VBA so please don't suggest conditional formatting as it wont achieve
what is required.

we have a sheet in the following format:


A B C D
101 10A "Some String" "Some String"
101 10A "Some String" "Some String"
101 50A "Some String" "Some String"
303 50A "Some String"
303 50A "Some String" "Some String"
303 1152A "Some String" "Some String"


Ok here is the problem... we wish to highlight (color) the background
of each row that has identical vales in column B. The sheet auto
updates from a data source, and is sorted on the values in column B,
therefore all identical values will remain together.

Any help would be appreciated as this is driving me mad.

Many thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA to highlight cells

Amcdee wrote:
Hi folks,

hope you can help with a little problem. The has to be achieved using
VBA so please don't suggest conditional formatting as it wont achieve
what is required.

we have a sheet in the following format:


A B C D
101 10A "Some String" "Some String"
101 10A "Some String" "Some String"
101 50A "Some String" "Some String"
303 50A "Some String"
303 50A "Some String" "Some String"
303 1152A "Some String" "Some String"


Ok here is the problem... we wish to highlight (color) the background
of each row that has identical vales in column B. The sheet auto
updates from a data source, and is sorted on the values in column B,
therefore all identical values will remain together.

Any help would be appreciated as this is driving me mad.

Many thanks in advance


Other solution:

Dim i As Integer, j As Integer

Range("B1").Activate
i = 1: j = 1
Do
If Range("B1").Offset(i, 0).Value = _
Range("B1").Offset(i - 1, 0).Value Then
Range("B1").Offset(i - 1, 0).Resize(2,1).EntireRow. _
Interior.ColorIndex = j
End If
If j = 11 Then j = 12 Else j = 11 ' Colors for row highlighting
i = i + 1
Loop Until Range("B1").Offset(i, 0).Value = ""

CoRrRan
--
Change NOSPAM to GMAIL
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default VBA to highlight cells

Try,

Sub bandit()
icolour = 3
lastrow = Range("b65536").End(xlUp).Row
Cells(1, 2).Select
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
For i = 2 To lastrow
Cells(i, 2).Select
If Cells(i, 2).Value = Cells(i, 2).Offset(1, 0).Value Then
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
Else
icolour = icolour + 1
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
End If
Next
End Sub

Mike

"Amcdee" wrote:

Hi folks,

hope you can help with a little problem. The has to be achieved using
VBA so please don't suggest conditional formatting as it wont achieve
what is required.

we have a sheet in the following format:


A B C D
101 10A "Some String" "Some String"
101 10A "Some String" "Some String"
101 50A "Some String" "Some String"
303 50A "Some String"
303 50A "Some String" "Some String"
303 1152A "Some String" "Some String"


Ok here is the problem... we wish to highlight (color) the background
of each row that has identical vales in column B. The sheet auto
updates from a data source, and is sorted on the values in column B,
therefore all identical values will remain together.

Any help would be appreciated as this is driving me mad.

Many thanks in advance


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default VBA to highlight cells

Of course i meant

If Cells(i, 2).Value = Cells(i, 2).Offset(-1, 0).Value Then

:)

Mike

"Mike H" wrote:

Try,

Sub bandit()
icolour = 3
lastrow = Range("b65536").End(xlUp).Row
Cells(1, 2).Select
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
For i = 2 To lastrow
Cells(i, 2).Select
If Cells(i, 2).Value = Cells(i, 2).Offset(1, 0).Value Then
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
Else
icolour = icolour + 1
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
End If
Next
End Sub

Mike

"Amcdee" wrote:

Hi folks,

hope you can help with a little problem. The has to be achieved using
VBA so please don't suggest conditional formatting as it wont achieve
what is required.

we have a sheet in the following format:


A B C D
101 10A "Some String" "Some String"
101 10A "Some String" "Some String"
101 50A "Some String" "Some String"
303 50A "Some String"
303 50A "Some String" "Some String"
303 1152A "Some String" "Some String"


Ok here is the problem... we wish to highlight (color) the background
of each row that has identical vales in column B. The sheet auto
updates from a data source, and is sorted on the values in column B,
therefore all identical values will remain together.

Any help would be appreciated as this is driving me mad.

Many thanks in advance




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA to highlight cells

On Jul 27, 10:56 am, Mike H wrote:
Of course i meant

If Cells(i, 2).Value = Cells(i, 2).Offset(-1, 0).Value Then

:)

Mike



"Mike H" wrote:
Try,


Sub bandit()
icolour = 3
lastrow = Range("b65536").End(xlUp).Row
Cells(1, 2).Select
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
For i = 2 To lastrow
Cells(i, 2).Select
If Cells(i, 2).Value = Cells(i, 2).Offset(1, 0).Value Then
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
Else
icolour = icolour + 1
ActiveCell.EntireRow.Select
Selection.Interior.ColorIndex = icolour
End If
Next
End Sub


Mike


"Amcdee" wrote:


Hi folks,


hope you can help with a little problem. The has to be achieved using
VBA so please don't suggest conditional formatting as it wont achieve
what is required.


we have a sheet in the following format:


A B C D
101 10A "Some String" "Some String"
101 10A "Some String" "Some String"
101 50A "Some String" "Some String"
303 50A "Some String"
303 50A "Some String" "Some String"
303 1152A "Some String" "Some String"


Ok here is the problem... we wish tohighlight(color) the background
of each row that has identical vales in column B. The sheet auto
updates from a data source, and is sorted on the values in column B,
therefore all identical values will remain together.


Any help would be appreciated as this is driving me mad.


Many thanks in advance- Hide quoted text -


- Show quoted text -


Thanks guys for your help just what I needed. :D

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
how to highlight cells ? Sul@MS New Users to Excel 3 March 24th 09 05:21 AM
how to highlight more related cells if cell highlight Jon Excel Discussion (Misc queries) 5 December 21st 08 01:06 PM
Highlight Cells Andrew Excel Discussion (Misc queries) 7 September 26th 05 08:50 PM
Highlight cells with ctrl-click but only un-highlight one cell hagan Excel Discussion (Misc queries) 5 May 27th 05 06:45 PM
Highlight cells Julian Campbell Excel Worksheet Functions 1 December 1st 04 10:49 PM


All times are GMT +1. The time now is 03:39 PM.

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

About Us

"It's about Microsoft Excel"