Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 08/11/2011, 17h10   #1
Membre éprouvé
 
Avatar de Runsh63
 
Homme Duc
Nihiliste
Inscription : mars 2011
Messages : 395
Détails du profil
Informations personnelles :
Nom : Homme Duc
Âge : 31
Localisation : France, Puy de Dôme (Auvergne)

Informations professionnelles :
Activité : Nihiliste
Secteur : Industrie

Informations forums :
Inscription : mars 2011
Messages : 395
Points : 419
Points : 419
Par défaut Trouver la dernière colonne utile

Bonjour,

Je bloque sur un truc tout bête, trouver la dernière ligne et la dernière colonne où se trouve les data dont j'ai besoin. Voilà ce que j'ai écrit.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Sub Compile_LCERO()
 
Dim StartRange As Range, Matrix As Range
Dim FirstRow As Byte, FirstCol As Byte, LastCol As Byte
Dim LastRow As Long
 
Application.ScreenUpdating = False
 
    'Nettoyer feuilles de destination des données
 
    With Sheets("Retreated TB")
        .UsedRange.EntireColumn.Delete
 
        With .Cells
            .HorizontalAlignment = xlLeft
            .NumberFormat = "General"
            .ColumnWidth = 10.71
            .RowHeight = 12.75
 
            With .Font
                .Name = "Arial"
                .Size = 10
                .FontStyle = "Normal"
            End With
 
            With .Borders
                .LineStyle = xlNone
            End With
 
            With .Interior
                .Pattern = xlNone
            End With
 
        End With
 
    End With
 
    With Sheets("Dataloader")
        .UsedRange.EntireColumn.Delete
 
        With .Cells
            .HorizontalAlignment = xlLeft
            .NumberFormat = "General"
            .ColumnWidth = 10.71
            .RowHeight = 12.75
 
            With .Font
                .Name = "Arial"
                .Size = 10
                .FontStyle = "Normal"
            End With
 
            With .Borders
                .LineStyle = xlNone
            End With
 
            With .Interior
                .Pattern = xlNone
            End With
 
        End With
 
    End With
 
    'Copier données dans onglet de retraitement
 
    With Sheets("Original TB")
 
    Set StartRange = .Cells.Find("101", LookIn:=xlValues)
    FirstRow = StartRange.Row
    FirstCol = StartRange.Column
    LastCol = .Range(.Cells(FirstRow, .Columns.Count)).End(xlToLeft).Column
    LastRow = .Range(.Cells(.Rows.Count, LastCol)).End(xlUp).Row
 
    End With
 
Application.CutCopyMode = False
Application.ScreenUpdating = True
 
End Sub
Je bloque pour définir LastCol et LastRow. Pouvez-vous m'aider SVP ?
D'avance merci !
__________________
Cordialement,

Runsh
Runsh63 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/11/2011, 17h19   #2
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 037
Points : 4 037
Bonjour,

Si j'ai bien suivi :

Code :
1
2
   LastCol = .Cells(FirstRow, .Columns.Count).End(xlToLeft).Column
   LastRow = .Cells(.Rows.Count, LastCol).End(xlUp).Row
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 08/11/2011, 17h27   #3
Membre éprouvé
 
Avatar de Runsh63
 
Homme Duc
Nihiliste
Inscription : mars 2011
Messages : 395
Détails du profil
Informations personnelles :
Nom : Homme Duc
Âge : 31
Localisation : France, Puy de Dôme (Auvergne)

Informations professionnelles :
Activité : Nihiliste
Secteur : Industrie

Informations forums :
Inscription : mars 2011
Messages : 395
Points : 419
Points : 419
Par défaut Offset ne fonctionne pas

Salut Daniel,

Merci pour ton aide, une fois de plus c'était tout bête...

Je bloque maintenant pour déterminer la plage à copier, à savoir (toujours avec le même code au début) :

Code :
Set Matrix = Union(.Cells(FirstRow, FirstCol), .Cells(FirstRow, LastCol.Offset(0, -3)), .Cells(LastRow, LastCol))
Il n'aime pas le LastCol.Offset. As-tu STP une idée pour que je puisse déterminer ma plage avec succès ? Dans l'absolu, je peux également définir une nouvelle variable qui serait basée sur LastCol est sur laquelle j'appliquerai le Offset... Mais ton puit de connaissance semble intarissable sur ce sujet, tu vas bien me sortir de la panade n'est-ce pas ?!?

D'avance merci pour ton aide !
__________________
Cordialement,

Runsh
Runsh63 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/11/2011, 17h33   #4
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 037
Points : 4 037
Il manque une parenthèse :

Code :
Set Matrix = Union(.Cells(FirstRow, FirstCol), .Cells(FirstRow, LastCol).Offset(0, -3)), .Cells(LastRow, LastCol))
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/11/2011, 19h04   #5
Expert Confirmé
 
Homme Philippe
ex Observeur CGG / Analyste prog.
Inscription : juin 2006
Messages : 1 710
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Localisation : France, Finistère (Bretagne)

Informations professionnelles :
Activité : ex Observeur CGG / Analyste prog.

Informations forums :
Inscription : juin 2006
Messages : 1 710
Points : 3 643
Points : 3 643
Salut, à consulter http://www.developpez.net/forums/d45...gnees-feuille/
__________________
Pensez à Voter, d'avance merci. ( Pouces en bas à la droite de Citer )
Balisez votre code après l'avoir indenté sous Excel via Smart Indenter
Autre utilitaire : MZ Tools 3.0 VBA

Contribution : Excel / Word / PDF avec Adobe Acrobat Pro / PDFCreator 1 2
kiki29 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2011, 11h14   #6
Membre éprouvé
 
Avatar de Runsh63
 
Homme Duc
Nihiliste
Inscription : mars 2011
Messages : 395
Détails du profil
Informations personnelles :
Nom : Homme Duc
Âge : 31
Localisation : France, Puy de Dôme (Auvergne)

Informations professionnelles :
Activité : Nihiliste
Secteur : Industrie

Informations forums :
Inscription : mars 2011
Messages : 395
Points : 419
Points : 419
Bonjour à vous deux, et merci pour vos réponses, c'est parfait
__________________
Cordialement,

Runsh
Runsh63 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 14h28.


 
 
 
 
Partenaires

Hébergement Web