Saltar al contenido
PROGRAMAR EN VBA MACROS DE EXCEL

Buscar datos en tres columnas con Macro de VBA


.

Este procedimiento de VBA o Macro de Excel busca un dato en la hoja 1, comparándolo con los datos de la hoja 1 en caso de no encontrarse el dato, éste es copiado en la hoja 3; para comparar

El código se encuentra a continuación, igualmente descargando el ejemplo lo podrás ver en funcionamiento, analizar, modificar y adaptar  a lo que tú estés realizando el  código está abierto sin ningún tipo de restricción.

Antes de seguir recomiendo leer un excelente libro sobre Excel que te ayudará operar las planillas u hojas de cálculo, haz click acá, si quieres aprender sobre Excel, en inglés, entonces debes hacer click here. Si lo que necesitas es aprender o profundizar sobre la programación de macros con VBA este es unos de los mejores cursos on line que he visto en internet.

  

La macro toma desde el primer al último registro de la hoja, lo compara con los registros de la hoja 2 en caso de no existir los copia en la hoja 3, en el vídeo a continuación encontrarás una explicación más gráfica y detallada del ejemplo presentado.


if (payload.eventType == ‘subscribe’) {
// Add code to handle subscribe event.
} else if (payload.eventType == ‘unsubscribe’) {
// Add code to handle unsubscribe event.
}
if (window.console) { // for debugging only
window.console.log(‘YT event: ‘, payload);
}
}

Sub BuscaDatosCoicidentes()
Application.ScreenUpdating = False
Dim fila, filat, uc1, uc2 As Integer
Dim d1, d2, d3, d4, d5, d6 As String
Dim b, con1, con2 As String

fila = 2
fila1 = 2
filat = 2

Sheets(«Hoja3»).Select
Range(«a2:XFD1048576»).Clear

uc1 = Sheets(«Hoja1»).Cells(1, Columns.Count).End(xlToLeft).Column
uc1 = uc1 + 1
uc2 = Sheets(«Hoja2»).Cells(1, Columns.Count).End(xlToLeft).Column
uc2 = uc2 + 1
While Sheets(«Hoja1»).Cells(fila, 1) <> Empty
d1 = Sheets(«Hoja1»).Cells(fila, 4).Text
d2 = Sheets(«Hoja1»).Cells(fila, 5).Text
d3 = Sheets(«Hoja1»).Cells(fila, 7).Text
con1 = d1 & d2 & d3
Sheets(«Hoja1»).Cells(fila, uc1) = con1
fila = fila + 1
Wend
fila = 2
While Sheets(«Hoja2»).Cells(fila, 1) <> Empty
d4 = Sheets(«Hoja2»).Cells(fila, 4).Text
d5 = Sheets(«Hoja2»).Cells(fila, 5).Text
d6 = Sheets(«Hoja2»).Cells(fila, 7).Text
con2 = d4 & d5 & d6
Sheets(«Hoja2»).Cells(fila, uc2) = con2
fila = fila + 1
Wend
fila = 2
While Sheets(«Hoja1»).Cells(fila, uc1) <> Empty
dato = Sheets(«Hoja2»).Cells(fila, uc2)
Set b = Sheets(«Hoja1»).Columns(uc1).Find(dato, LookIn:=xlValues, Lookat:=xlWhole)

If b Is Nothing Then
Sheets(«Hoja2»).Select
Rows(fila).Select
Selection.Copy
Sheets(«Hoja3»).Select
Cells(filat, 1).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
filat = filat + 1
End If
fila = fila + 1
Wend
Sheets(«Hoja3»).Columns(5).Select
Selection.NumberFormat = «#,##0»
Application.CutCopyMode = False
Sheets(«Hoja1»).Columns(uc1).Clear
Sheets(«Hoja2»).Columns(uc2).Clear
Sheets(«Hoja3»).Columns(uc2).Clear
Set b = Nothing
Application.ScreenUpdating = False
End Sub

Si te fue de utilidad puedes INVITARME
UN CAFÉ
 y de esta manera ayudar a seguir
manteniendo la página, CLICK para descargar en ejemplo en forma gratuita.


.

If this post was
helpful INVITE ME A COFFEE and so help keep
up the page, CLICK to download free example.

Si te gustó por favor compártelo con tus amigos
If you liked please share it with your friends