ParanoidAndroid
Board Regular
- Joined
- Jan 24, 2011
- Messages
- 50
Hi Excel Experts
I really appreciate your help with this
I have adapted this excel code i found online. This code looks for duplicates in column V and then deletes that row with the duplicate.
There is however a slight quirk -
The sheet has a range (A:U) which is linked to a database in Sharepoint. So when deleting the row based on duplicate cell in column V I need to
1) Delete the duplicate cell in column V and shift up that cell
ie: Range("V" & CStr(LTestLoop)).Select
Range("V" & CStr(LTestLoop)).Delete Shift:=xlUp
2) select a cell from the row I want to delete in the linked range and delete that row
ie. something like Selection.ListObject.ListRows.Delete
This is because it doesnt seem possible to use EntireRow.Delete when you have a linked range(to Sharepoint).
He is the code i've adapted...it seems to work except i'm not sure how to adapt 2) see "delete duplicates
I really appreciate your help with this
I have adapted this excel code i found online. This code looks for duplicates in column V and then deletes that row with the duplicate.
There is however a slight quirk -
The sheet has a range (A:U) which is linked to a database in Sharepoint. So when deleting the row based on duplicate cell in column V I need to
1) Delete the duplicate cell in column V and shift up that cell
ie: Range("V" & CStr(LTestLoop)).Select
Range("V" & CStr(LTestLoop)).Delete Shift:=xlUp
2) select a cell from the row I want to delete in the linked range and delete that row
ie. something like Selection.ListObject.ListRows.Delete
This is because it doesnt seem possible to use EntireRow.Delete when you have a linked range(to Sharepoint).
He is the code i've adapted...it seems to work except i'm not sure how to adapt 2) see "delete duplicates
Code:
Sub TestForDuplicates()
Dim LLoop As Integer
Dim LTestLoop As Integer
Dim Lrows As Integer
Dim LRange As String
Dim LCnt As Integer
'Column values
Dim LColV_1 As String
Lrows = Range("V2").End(xlDown).Row
LLoop = 2
LCnt = 0
'Check until last used row in column V
While LLoop <= Lrows
LColV_1 = "V" & CStr(LLoop)
If Len(Range(LColV_1).Value) > 0 Then
'Test each value for uniqueness
LTestLoop = LLoop + 1
While LTestLoop <= Lrows
If LLoop <> LTestLoop Then
LColV_2 = "V" & CStr(LTestLoop)
'Value has been duplicated in another cell of the same coluumn which is column V)
If (Range(LColV_1).Value = Range(LColV_2).Value) _
Then
'Delete the duplicate
Rows(CStr(LTestLoop) & ":" & CStr(LTestLoop)).Select
Selection.ListObject.ListRows(LTestLoop).Delete 'deletes a row within the range linked to sharepoint database
Rows(CStr(LTestLoop) & ":" & CStr(LTestLoop)).Select
Range("V" & CStr(LTestLoop)).Select 'deletes the cells tested in column that is outside the linked sharepoint database otherwise it gets stuck in a loop
Range("V" & CStr(LTestLoop)).Delete Shift:=xlUp
'Decrement counter since row was deleted
LTestLoop = LTestLoop - 1
LCnt = LCnt + 1
End If
End If
LTestLoop = LTestLoop + 1
Wend
End If
LLoop = LLoop + 1
Wend
End Sub