Inside Colonnes A1: A10000 sont toutes remplies de 18 caractères Exemple: aaaaaaaaaaaaaaaaaaaa
Le VBA suivant vous aidera à les diviser dans leurs colonnes respectives en fonction de leur longueur spécifique requise. Cependant, VBA pourrait ne pas réagir en raison d'une grande quantité d'informations. Aurait besoin d'une aide sur l'amélioration? P>
Sub looptest()
Dim rng As Range
Dim cCel As Range
Dim i As Long
Set rng = Range("A1: A10000")
i = 1
For Each cCel In rng
Cells(i, 2).Value = Left(Cells(i, 1).Value, 2)
Cells(i, 3).Value = Mid(Cells(i, 1).Value, 3, 1)
Cells(i, 4).Value = Mid(Cells(i, 1).Value, 4, 2)
Cells(i, 5).Value = Mid(Cells(i, 1).Value, 6, 1)
Cells(i, 6).Value = Mid(Cells(i, 1).Value, 7, 2)
Cells(i, 7).Value = Mid(Cells(i, 1).Value, 9, 2)
Cells(i, 8).Value = Mid(Cells(i, 1).Value, 11, 3)
Cells(i, 9).Value = Mid(Cells(i, 1).Value, 14, 1)
Cells(i, 10).Value = Mid(Cells(i, 1).Value, 15, 3)
Cells(i, 11).Value = Mid(Cells(i, 1).Value, 16, 1)
i = i + 1
Next cCel
End Sub
3 Réponses :
Avant la boucle pour la boucle, ajoutez et après cela, p>
Entendu. Merci pour votre conseil
Vous n'avez pas besoin d'une boucle et si vous souhaitez accélérer cela, vous pouvez également passer d'abord des fonctionnalités d'abord avec le code suivant P> ' Procedure : TurnOffFunctionality
' Source : www.TheExcelVBAHandbook.com
' Author : Paul Kelly
' Purpose : Turn off automatic calculations, events and screen updating
Private Sub TurnOffFunctionality()
Application.Calculation = xlCalculationManual
Application.DisplayStatusBar = False
Application.EnableEvents = False
Application.ScreenUpdating = False
End Sub
' Procedure : TurnOnFunctionality
' Source : www.TheExcelVBAHandbook.com
' Author : Paul Kelly
' Purpose : turn on automatic calculations, events and screen updating
Private Sub TurnOnFunctionality()
Application.Calculation = xlCalculationAutomatic
Application.DisplayStatusBar = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Merci pour votre conseil
L'utilisation de la variante est rapide.
Sub test()
Dim rng As Range
Dim i As Long, n As Long
Dim vDB As Variant, vR() As Variant
Set rng = Range("A1: A10000")
vDB = rng
n = UBound(vDB, 1)
ReDim Preserve vR(1 To n, 1 To 10)
For i = 1 To n
vR(i, 1) = Left(vDB(i, 1), 2)
vR(i, 2) = Mid(vDB(i, 1), 3, 1)
vR(i, 3) = Mid(vDB(i, 1), 4, 2)
vR(i, 4) = Mid(vDB(i, 1), 6, 1)
vR(i, 5) = Mid(vDB(i, 1), 7, 2)
vR(i, 6) = Mid(vDB(i, 1), 9, 2)
vR(i, 7) = Mid(vDB(i, 1), 11, 3)
vR(i, 8) = Mid(vDB(i, 1), 14, 1)
vR(i, 9) = Mid(vDB(i, 1), 15, 3)
vR(i, 10) = Mid(vDB(i, 1), 16, 1)
Next i
Range("b1").Resize(n, 10) = vR
End Sub
Code Débogage à Redim Préserver VR (1 à N, 1 à 10) ?? Indice hors de portée. Sry je ne suis pas familier avec la variante
@Clifford, j'ai mal saisi n = ubound (VDB, 1) code>. J'ai édité.
@Clifford, même si vous ne connaissez pas le tableau de variante, il est inévitable que cela soit rapide.
C'est certainement.
Cela pourrait aider à améliorer la durée de l'exécution de votre code en incluant
application.screenupdating = false code> etapplication.calculation = xlcalcultmanual 'avant votre code> pour ... prochaine` boucle et ensuite défini Retour àApplication.ScreenupDating = true code> et `application.calculation = xlcalculatureautomatic '- Cet article de Spreadchecheguru peut aider à expliquer davantage.