Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how can I compare two columns | Excel Worksheet Functions | |||
compare two columns | Excel Discussion (Misc queries) | |||
COMPARE 2 COLUMNS | Excel Discussion (Misc queries) | |||
How do I write a VBA code in excel that will compare two columns . | Excel Worksheet Functions | |||
Compare 3 columns | Excel Programming |