buen dia
en esta macro copio lo que hay en la celda "f5" y la pego el columna "A" de otra hoja
quisiera me pudiera ayudar para que la macro me mande un mensaje de error y no copie el dato de la celda "f5" si esta duplicado en la otra hoja de la colunma "A"
Saludos anexo macro espero me puedan ayudar
Sub Copy_NUM_RSP()
Dim SourceRange As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'fill in the Source Sheet and range
Set SourceRange = Sheets("PPS Format Front").Range("F5")
'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("BASE DE DATOS")
'Lr = LastRow(DestSheet)
Lr = DestSheet.Cells(Rows.Count, "A").End(xlUp).Row
'With the information from the LastRow function we can
'create a destination cell and copy/paste the source range
Set DestRange = DestSheet.Range("A" & Lr + 1)
SourceRange.Copy DestRange
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub





Es una pena que Excel no tenga la posibilidad de clave única, claro que entonce sería una base de datos y no una hoja de cálculo.
¿cómo comprobar si está duplicado?
Si está duplicado quiere decir que ya existe otro valor igual en el destino, así que por ejemplo si utilizas la función CONTAR.SI para ver cuántos resultados tienes iguales te daría 0 si no está y 1 o más de uno si ya lo tienes.
para utilizar esta función desde el código utiliza Application.WorkSheetFunction.CountIf
por ejemplo:
If Application.WorksheetFunction.CountIf(DestSheet.Range("A:A"), SourceRange.Value) > 0 Then ...
------
Ya sé Excel, pero necesito más.