Utiliser un code pour une feuille "x"

Fermé
sarahaensa - Modifié par pijaku le 10/06/2015 à 14:45
michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 - 10 juin 2015 à 09:40
bonjour
j'ai rien un code vba ,et je veux l'adapter pour faire la manup sur pour une feuille "master" :
Dim Lg%, cL%, A%, i%, x
    x = Time
    Application.ScreenUpdating = False
    cL = Cells(1, 2000).End(xlToLeft).Column
    For A = 1 To cL
        Lg = Cells(65536, A).End(xlUp).Row
         For i = Lg To 1 Step -1
            If Cells(i, A) = "" Then
                Cells(i, A).Delete Shift:=xlUp
            End If
        Next i
    Next A
    MsgBox ("temps macro = " & Format(Time - x, "hh:mm:ss"))
A voir également:

1 réponse

michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 303
Modifié par michel_m le 10/06/2015 à 09:35
Bonjour

1/pas besoin de boucler pour supprimer une ligne si cellule dans col A et/ou B et/ou X... vide ;o)
Option Explicit
Const Master As String = "Feuil1"
'------------------
Sub Supprimer_si_vide()
Dim Ligne As Integer, Col As Byte
'On Error resume next
With Sheets(Master)
Col = .Rows(1).Find(what:="*", searchdirection:=xlPrevious).Column
Ligne = .Columns("A").Find(what:="*", searchdirection:=xlPrevious).Row
.Range(.Cells(1, 1), .Cells(Ligne, Col)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub

durée: instantanée

2/ pour mesurer une durée
dim start as single
start=timer
...
le code
....
Msgbox "durée: " & timer-start & " sec."

3/ pour faciliter la maintenance
Dim variable as Integer plus parlant que dim variable%

EDit 9:36H
adapté code pour plusieurs colonnes
Michel
0
merci pour votre reponse , mais je sais pas comment untiser le nom de ma feuille dans mon code vba
0
michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 303 > sarahaensa
10 juin 2015 à 09:40
re,
je viens d'adapter le code dans ma 1° réponse (onglet, plusieurs colonnes) mais le revoila
Option Explicit
Const Master As String = "Feuil1"
'------------------
Sub Supprimer_si_vide()
Dim Ligne As Integer, Col As Byte
'On Error resume next
With Sheets(Master)
Col = .Rows(1).Find(what:="*", searchdirection:=xlPrevious).Column
Ligne = .Columns("A").Find(what:="*", searchdirection:=xlPrevious).Row
.Range(.Cells(1, 1), .Cells(Ligne, Col)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub
0