#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Highlight

Hi, everyone!!

I have a worksheet that has data in column A and the other in column B. Now
I want a VBA code that would higlight the data in column A if matches with
that in Column B. The code should search the whole A column for a data in B1
then start for B2.
I have a code mentioned below but it takes a long time but it works.
Any can help me for a quick code process?

Private Sub CommandButton1_Click()

Dim I As Integer

Worksheets("Sheet1").Activate
For I = 6 To 877
For J = 6 To 877
If Cells(I, 2).Value = Cells(J, 22).Value Then
Cells(I, 2).Interior.ColorIndex = 3
ElseIf Cells(I, 2).Value = "" Then
Cells(I, 2).Interior.ColorIndex = 4
End If
Next J
Next I
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Highlight

Hi,

Try this

Private Sub CommandButton1_Click()
Dim LastRowA as long
Dim LastRowB as long
Dim MyRangeA as range, MyRangeB as range, c as range
Set sht = Sheets("Sheet1")
lastrowA = sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
lastrowB = sht.Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set MyRangeA = sht.Range("A6:A" & lastrowA)
Set MyRangeB = sht.Range("B6:B" & lastrowB)
For Each c In MyRangeA
If WorksheetFunction.CountIf(MyRangeB, c.Value) 0 Then
c.Interior.ColorIndex = 3
Else
c.Interior.ColorIndex = 4
End If
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Msgbox "Data not found"" wrote:

Hi, everyone!!

I have a worksheet that has data in column A and the other in column B. Now
I want a VBA code that would higlight the data in column A if matches with
that in Column B. The code should search the whole A column for a data in B1
then start for B2.
I have a code mentioned below but it takes a long time but it works.
Any can help me for a quick code process?

Private Sub CommandButton1_Click()

Dim I As Integer

Worksheets("Sheet1").Activate
For I = 6 To 877
For J = 6 To 877
If Cells(I, 2).Value = Cells(J, 22).Value Then
Cells(I, 2).Interior.ColorIndex = 3
ElseIf Cells(I, 2).Value = "" Then
Cells(I, 2).Interior.ColorIndex = 4
End If
Next J
Next I
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 376
Default Highlight

Hi

Use the Countif function to speed the process

Private Sub CommandButton1_Click()

Dim i As Integer

Worksheets("Sheet1").Activate
For i = 6 To 877

If WorksheetFunction.CountIf(Range("A6:A877") _
, Cells(i, 2).Value) 0 Then
Cells(i, 2).Interior.ColorIndex = 3
ElseIf Cells(i, 2).Value = "" Then
Cells(i, 2).Interior.ColorIndex = 4
End If
Next i
End Sub

--
Regards
Roger Govier

Msgbox Data not found wrote:
Hi, everyone!!

I have a worksheet that has data in column A and the other in column B. Now
I want a VBA code that would higlight the data in column A if matches with
that in Column B. The code should search the whole A column for a data in B1
then start for B2.
I have a code mentioned below but it takes a long time but it works.
Any can help me for a quick code process?

Private Sub CommandButton1_Click()

Dim I As Integer

Worksheets("Sheet1").Activate
For I = 6 To 877
For J = 6 To 877
If Cells(I, 2).Value = Cells(J, 22).Value Then
Cells(I, 2).Interior.ColorIndex = 3
ElseIf Cells(I, 2).Value = "" Then
Cells(I, 2).Interior.ColorIndex = 4
End If
Next J
Next I
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Highlight


Thanks Mike!! It worked!!!
"Mike H" wrote:

Hi,

Try this

Private Sub CommandButton1_Click()
Dim LastRowA as long
Dim LastRowB as long
Dim MyRangeA as range, MyRangeB as range, c as range
Set sht = Sheets("Sheet1")
lastrowA = sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
lastrowB = sht.Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set MyRangeA = sht.Range("A6:A" & lastrowA)
Set MyRangeB = sht.Range("B6:B" & lastrowB)
For Each c In MyRangeA
If WorksheetFunction.CountIf(MyRangeB, c.Value) 0 Then
c.Interior.ColorIndex = 3
Else
c.Interior.ColorIndex = 4
End If
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Msgbox "Data not found"" wrote:

Hi, everyone!!

I have a worksheet that has data in column A and the other in column B. Now
I want a VBA code that would higlight the data in column A if matches with
that in Column B. The code should search the whole A column for a data in B1
then start for B2.
I have a code mentioned below but it takes a long time but it works.
Any can help me for a quick code process?

Private Sub CommandButton1_Click()

Dim I As Integer

Worksheets("Sheet1").Activate
For I = 6 To 877
For J = 6 To 877
If Cells(I, 2).Value = Cells(J, 22).Value Then
Cells(I, 2).Interior.ColorIndex = 3
ElseIf Cells(I, 2).Value = "" Then
Cells(I, 2).Interior.ColorIndex = 4
End If
Next J
Next I
End Sub


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 more related cells if cell highlight Jon Excel Discussion (Misc queries) 5 December 21st 08 01:06 PM
Highlight if ... [email protected] Excel Worksheet Functions 3 June 28th 07 09:52 PM
Highlight active cell and de-highlight previous cell dmbuso Excel Programming 3 April 7th 07 04:22 PM
Highlight pjy Excel Discussion (Misc queries) 0 August 29th 06 05:02 PM
Highlight cells with ctrl-click but only un-highlight one cell hagan Excel Discussion (Misc queries) 5 May 27th 05 06:45 PM


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

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"