psbrown
MIS
- Oct 16, 2001
- 40
Hi I am new to VBA but have a done other languages in the past. I want to remove duplicates in column p on an Excel worksheet.
I have developled the code below to loop through the column.
my test data is 2 rows with the value of 2-2005(one copied from the other)
my problem is that my the line below marked********
if target = subject does not seem to find the equivlence and runs the msgbox ("else") statemen even though the msgbox's above show correct values for subjct and target.
What is wrong with this statment please I am stuck?
Sub DupDelete()
Dim mark As Integer
Dim Target As String
Dim Subject As String
Dim PNoRows As Integer
'Count No Rows in Column P
With Worksheets("SFS")
PNoRows = .Cells(.Rows.Count, "P").End(xlUp).Row 'count number of rows
End With
'Loop though Column check each cell against cells below and overwrite any duplicates with blank
For i = 1 To PNoRows
Target = Worksheets("SFS").Cells(i, "p").Value
mark = i + 1
For m = mark To PNoRows
MsgBox ("mark = " & mark)
Subject = Worksheets("SFS").Cells(m, "p").Value
MsgBox ("Subject =" & Subject)
MsgBox ("target =" & Target)
********If Taget = Subject Then
Worksheets("SFS").Cells(m, "p").Value = "---"
MsgBox ("swapping")
Else
MsgBox ("else")
End If
Next
Next
End Sub
I have developled the code below to loop through the column.
my test data is 2 rows with the value of 2-2005(one copied from the other)
my problem is that my the line below marked********
if target = subject does not seem to find the equivlence and runs the msgbox ("else") statemen even though the msgbox's above show correct values for subjct and target.
What is wrong with this statment please I am stuck?
Sub DupDelete()
Dim mark As Integer
Dim Target As String
Dim Subject As String
Dim PNoRows As Integer
'Count No Rows in Column P
With Worksheets("SFS")
PNoRows = .Cells(.Rows.Count, "P").End(xlUp).Row 'count number of rows
End With
'Loop though Column check each cell against cells below and overwrite any duplicates with blank
For i = 1 To PNoRows
Target = Worksheets("SFS").Cells(i, "p").Value
mark = i + 1
For m = mark To PNoRows
MsgBox ("mark = " & mark)
Subject = Worksheets("SFS").Cells(m, "p").Value
MsgBox ("Subject =" & Subject)
MsgBox ("target =" & Target)
********If Taget = Subject Then
Worksheets("SFS").Cells(m, "p").Value = "---"
MsgBox ("swapping")
Else
MsgBox ("else")
End If
Next
Next
End Sub