Code: Select all
Sub removeduplicateRows()
dim vc,founddeletes as boolean,i,t,col,sts,cc as new collection,n,doc
doc = thiscomponent
vc = doc.currentcontroller.viewcursor
if isempty(vc.texttable) then
msgbox "First click in a texttable in the column you want to use to filter out duplicate rows."
exit sub
end if
t = vc.texttable
doc.lockcontrollers
on error goto hr
col = asc(vc.cell.cellname)-65
n= t.rows.count -1
for i = n to 0 step -1
st=t.getCellByPosition(col,i).string
if isincollection(cc,st) = false then
cc.add "",st
else
if not founddeletes then
doc.undomanager.enterUndoContext("Delete Duplicates")
founddeletes = true
end if
t.rows.removebyindex(i,1)
end if
next
hr:
doc.unlockcontrollers
if founddeletes then doc.undomanager.leaveUndoContext
End Sub
function isincollection(cc,st) as boolean
dim a
on error goto hr
a =cc.item(st)
isincollection=true
exit function
hr:
end function
Code: Select all
Sub removeduplicateFullRows()
dim vc,founddeletes as boolean,i,j,t,ubcolumns,sts,cc as new collection,n,doc
doc = thiscomponent
vc = doc.currentcontroller.viewcursor
if isempty(vc.texttable) then
msgbox "First click in a texttable to remove duplicate full rows"
exit sub
end if
t = vc.texttable
doc.lockcontrollers
on error goto hr
n= t.rows.count -1
ubcolumns=t.columns.count -1
for i = n to 0 step -1
st = ""
for j= 0 to ubcolumns
st=st & t.getCellByPosition(j,i).string
next
if isincollection(cc,st) = false then
cc.add "",st
else
if not founddeletes then
doc.undomanager.enterUndoContext("Delete Duplicates")
founddeletes = true
end if
t.rows.removebyindex(i,1)
end if
next
hr:
doc.unlockcontrollers
if founddeletes then doc.undomanager.leaveUndoContext
End Sub