Matching contents of a cell full of text

B

brien downie

I'm trying to write a macro that will compare the contents of two
nearby cells to see if they are identical. The cells all contain the
names of creative placements, so they are not numerical values.

I'm thinking something like,

sub test

if activecell.offset(5, -1) = activecell.offset(5,-2) then
Msgbox("These are the same")
' And then do any action I want
Else
Msgbox("These are not the same")
End if
End sub

does anybody know how to effectively do that first If statement?

Thanks,
-Brien
 
G

Gerencsér Gábor

I suggest to try the following:

Sub CompareCells()
'Please note this macro assumes the entries are continuous.
'(Means there are no empty cells in between.)
Range("A1").Select 'This is your starting cell.
'Please edit cell address to fit your needs.
Do Until ActiveCell = Empty
If ActiveCell Like ActiveCell(0, 1) Then _
ActiveCell.Offset(0, 5).FormulaR1C1 = "Identical"
'Edit the offset as it fits your sheet.
Else
ActiveCell.Offset(0, 5).FormulaR1C1 = "Different"
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top