Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Optimizar tiempo en ejecución de una macro

publicado

Estimados Amigos,

 

Buenas tardes, tengo una pregunta sobre como podría optimizar una macro que recorre 300.000 registros y concatena información con el siguiente código:

 

Sub ConcatenaColumnas()
Dim numzeros As String
numzeros = "0000000000"

Range("A:B").Select
Selection.NumberFormat = "@"

Range("E3").Select

'------------------Columna Validación--------------------------------------------------------------------------------------------
   Do While ActiveCell <> ""  'Bucle hasta la celda este en blanco

''de la celda activada retroceder xx números (0, -xx) a la izquierda y escribir fórmula
      ActiveCell.Offset(0, -4).FormulaR1C1 = _
         Format(ActiveCell.Offset(0, 0), "dd") & Format(ActiveCell.Offset(0, 0), "mm") & Format(ActiveCell.Offset(0, 0), "yyyy") _
         & Left(numzeros, 10 - Len(ActiveCell.Offset(0, 3))) & ActiveCell.Offset(0, 3) _
         & Left(numzeros, 10 - Len(ActiveCell.Offset(0, 4))) & ActiveCell.Offset(0, 4) _
         & ActiveCell.Offset(0, 5) _
         & ActiveCell.Offset(0, 6)
         
    ActiveCell.Offset(0, -3).FormulaR1C1 = _
            ActiveCell.Offset(0, 2) _
            & ActiveCell.Offset(0, 6) _

    ActiveCell.Offset(1, 0).Select
   Loop

End Sub

El código recorre la celda del rango "e3" validando que tenga información y concatena creando una cadena de texto en el rango (a1), sin embargo ha tardado 12 minutos en cumplir la tarea.

Alguien podría darme una mano para poder optimizar el código, sin recurrir a power bi o pivot?

 

De antemano muchas gracias.

Featured Replies

publicado
  • Autor
Hace 49 minutos , avalencia dijo:

Hola

Envía al menos algunos de los registros para darnos idea de qué es lo que tienes ahí y cómo necesitas que quede.

Abraham Valencia

Hola Amigo,

Muchas gracias por tu respuesta, el archivo es el siguiente:

 

libroadcccc.xlsm

publicado
Hace 4 horas, Luis Antonio Torres dijo:

optimizar una macro que recorre 300.000 registros y concatena

soy fanático de los "no bucles" (cuando se puede) y esta pudiera ser una alternativa viable (?)

Sub FasterJoin()
  With Range("a3:a" & Cells(Rows.Count, 5).End(xlUp).Row)
    .Formula = "=""'""&text(e3,""ddmm"")&year(e3)&right(""0000000000""&h3,10)&right(""0000000000""&i3,10)&j3&k3"
    .Offset(, 1).Formula = "=g3&k3"
    With .Resize(, 2): .Value = .Value: End With
  End With
End Sub

 

publicado
  • Autor
Hace 14 horas, Héctor Miguel dijo:

soy fanático de los "no bucles" (cuando se puede) y esta pudiera ser una alternativa viable (?)


Sub FasterJoin()
  With Range("a3:a" & Cells(Rows.Count, 5).End(xlUp).Row)
    .Formula = "=""'""&text(e3,""ddmm"")&year(e3)&right(""0000000000""&h3,10)&right(""0000000000""&i3,10)&j3&k3"
    .Offset(, 1).Formula = "=g3&k3"
    With .Resize(, 2): .Value = .Value: End With
  End With
End Sub

 

Muchas gracias por la respuesta, la probaré.

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.