Sub CruceFacturasDolares()
Dim wbMov As Workbook, wbFact As Workbook
Dim wsMov As Worksheet, wsFact As Worksheet
Dim pathFact As String, ultimaFila As Long
Dim i As Long, j As Long, seccion As String
Dim filaInicio As Long, filaFin As Long
Dim nombre As String, tipoOp As String, producto As String, monto As Currency
Dim nombreF As String, tipoOpF As String, productoF As String, montoF As
Currency, estado As String, nroFactura As String
Dim ultimaCol As Long
Dim rngFact As Range
' Abrir el archivo de facturación
pathFact = [Link]("Archivos Excel (*.xlsx), *.xlsx", ,
"Selecciona el archivo FACTURACIÓN")
If pathFact = "Falso" Then Exit Sub
Set wbFact = [Link](pathFact)
Set wsFact = [Link]("facturación local")
' Activar el archivo de movimientos
Set wbMov = ThisWorkbook
Set wsMov = [Link]("movimientos gc")
' Buscar secciones en movimientos
For i = 1 To [Link]([Link], 1).End(xlUp).Row
seccion = [Link](i, 1).Value
If seccion = "Inversiones Dólares - Ingresos" Or seccion = "Cierre de Mes
Dolares" Then
filaInicio = i + 2 ' La cabecera está una fila después del título
filaFin = filaInicio
' Encontrar fin de la sección (hasta que A esté vacía o empiece otra
sección)
Do While [Link](filaFin, 1).Value <> "" Or [Link](filaFin,
2).Value <> ""
filaFin = filaFin + 1
Loop
filaFin = filaFin - 1
' Agregar columna Fact si no existe
ultimaCol = [Link](filaInicio - 1,
[Link]).End(xlToLeft).Column + 1
[Link](filaInicio - 1, ultimaCol).Value = "Fact"
' Recorrer filas de la sección
For j = filaInicio To filaFin
nombre = Trim([Link](j, 2).Value)
tipoOp = Trim([Link](j, 3).Value)
producto = Trim([Link](j, 10).Value)
monto = Val([Link](j, 11).Value)
' Buscar en facturación
Set rngFact = [Link]
For Each celda In [Link](1).Cells
If [Link] = "FACTURADOS DÓLARES" And seccion =
"Inversiones Dólares - Ingresos" _
Or [Link] = "CANCELADOS DOLARES" And seccion = "Cierre de
Mes Dolares" Then
' Leer encabezados (2 filas abajo del título)
Dim filaEncabezado As Long
filaEncabezado = [Link] + 2
Dim k As Long
For k = filaEncabezado + 1 To filaEncabezado + 1000
If [Link](k, 1).Value = "" Then Exit For
nombreF = Trim([Link](k, 1).Value)
estado = Trim([Link](k, 2).Value)
tipoOpF = Trim([Link](k, 3).Value)
productoF = Trim([Link](k, 7).Value)
montoF = Val([Link](k, 9).Value)
nroFactura = [Link](k, 11).Value
If estado = "FACTURADO" And _
nombreF = nombre And tipoOpF = tipoOp And productoF
= producto And montoF = monto Then
[Link](j, ultimaCol).Value = nroFactura
Exit For
End If
Next k
End If
Next celda
Next j
End If
Next i
MsgBox "Cruce de facturas completado con éxito 🧾✅", vbInformation
End Sub