View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] amitmandalia@gmail.com is offline
external usenet poster
 
Posts: 5
Default Comparing Cell values in two sheets within the same workbook

it fails at the b line.

if i change the target cell formats to the same, would that help?

On 16 Feb, 13:00, Joel wrote:
is it failing at the a = or b = lines? the line it fails at should be
highlight in yellow. try again and take out .value. It seems like the
format of the two cell being comparred are not the same.



" wrote:
the data is all in the same format, i have to compare the numbers in a
column in sheet 1 with the numbers in the column in the sheet called
'mis tool'


im only a beginner at writing macro code.


i've changed the code to include the a and b as shown below, but now i
get an error '438'


"Object does't support this property or method"


any ideas?


Sub Macro1()


Sheets("Sheet1").Select
Range("H2").Select
Sheets("mis tool").Select
Range("F2").Select
Sheets("Sheet1").Select
Do
Do While ActiveCell < 0
a = ActiveCell.Value
b = Sheets("mis tool").ActiveCell.Value
If a = b Then
Sheets("mis tool").Select
ActiveCell.Offset(0, 3).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
ActiveCell.Offset(0, 13).Select
ActiveSheet.Paste
ElseIf a < b Then
Sheets("Sheet1").Select
ActiveCell.Offset(1, 0).Select
End If
Loop
If ActiveCell = 0 Then
Sheets("Sheet1").Select
Range("H2").Select
Sheets("mis tool").Select
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = 0
End Sub


On 16 Feb, 11:47, Joel wrote:
I sthe data in the same format? If it is strings then use strcomp.


when I havve this problem I add extra code to debug the problem
I added a & b before the if staement. Put a break point (F9) at the If
statement and check the values of a & b. this should find the problem. You
also may need to add the .value to the If statement.


a = ActikveCell.value
b = Sheets("mis tool").ActiveCell.value


If ActiveCell = Sheets("mis tool").ActiveCell Then


" wrote:
This is the code i have.


i want to compare a range of values in column H in sheet 1 with a
column that is in the sheet called 'mis tool'


I have the code looping down the range in sheet 1 and comparing to the
1st value in sheet 'mis tool', once the range in sheet 1 has run
throught, the cell selected in 'mis tool' will move down 1 and then it
will re-check for similar values.


the problem i have is that i can't get the code to pick up on entries
that are equal to each other.


I need an if statement that can compare the selected cell in sheet 1
with the selected cell in sheet 'mis tool', all cells are numerical
entries


the code as it is stops at the first IF statement, but otherwise does
what i need it to do.


any ideas?


Sub Macro1()


Sheets("Sheet1").Select
Range("H2").Select
Sheets("mis tool").Select
Range("F2").Select
Sheets("Sheet1").Select
Do
Do While ActiveCell < 0
If ActiveCell = Sheets("mis tool").ActiveCell Then
Sheets("mis tool").Select
ActiveCell.Offset(0, 3).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
ActiveCell.Offset(0, 13).Select
ActiveSheet.Paste
ElseIf ActiveCell < Sheets("mis tool").ActiveCell Then
Sheets("Sheet1").Select
ActiveCell.Offset(1, 0).Select
End If
Loop
If ActiveCell = 0 Then
Sheets("Sheet1").Select
Range("H2").Select
Sheets("mis tool").Select
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = 0
End Sub- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -