LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Help with VB code to compare two columns

I have written VB code to compare values in columns B and S. If a value in B
is not found in S then the text color for value in B is changed to red. The
process continues until there are no more values in B. The code is given
below:

Range("B2").Activate
Dim ctr As Integer
ctr = 0
Set rng = Range("B2")
Dim x As String
x = ActiveCell.Text
Debug.Print x

While x < ""

Columns("S:S").Select
On Error GoTo errorhandler
Selection.Find(What:=x, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate


errorhandler:
If x < ActiveCell.Value Then
MsgBox ("Current Value is not found")
rng = Worksheets("Sheet3").Cells(2, 2).Offset(ctr, 0).Activate
Selection.Font.ColorIndex = 3
End If

ctr = ctr + 1
rng = Worksheets("Sheet3").Cells(2, 2).Offset(ctr, 0).Activate
x = ActiveCell.Text
Wend

This is what is happening. For the first value in B not found in S the code
works okay, but for the next value not found in S, the following error is
generated "Object Variable or With block not set". How can I overcome this
problem (I even have an error handler in place). Importantly what is causing
this error.

Thanks in advance for your help.

Farooq
 
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 can I compare two columns snwwlf Excel Worksheet Functions 1 November 7th 08 12:31 AM
compare two columns Theresa Excel Discussion (Misc queries) 5 April 11th 08 11:02 PM
COMPARE 2 COLUMNS Gary''s Student Excel Discussion (Misc queries) 0 June 7th 06 07:53 PM
How do I write a VBA code in excel that will compare two columns . PenelopeinCinci Excel Worksheet Functions 2 April 14th 05 05:27 PM
Compare 3 columns broogle Excel Programming 0 March 18th 05 01:54 AM


All times are GMT +1. The time now is 11:32 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"