Bonjour, je cherche à remplacer des nombres stockés sous forme de texte par ces mêmes nombres stockés sous forme de nombre et ceci de façon conditionnées par la valeur d'une cellule.
Les nombres en question se trouvent dans la plage G2:DU1000 et l'action doit être appliquée uniquement dans les lignes pour lesquelles DV="FAUX" (donné par le résultat d'une formule.
Le code avec lequel je travaille:
Pour l'instant, il applique parfaitement l'action mais à partir de la dernière cellule de la colonne A contenant une valeur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Dim rg As Range, rg2 As Range, sh As Worksheet, t() Dim i&, j& Set sh = Sheets("RECUP") Set rg = sh.Range(sh.Range("G" & Application.Rows.Count).End(xlUp), sh.Range("DU" & Application.Rows.Count).End(xlUp)) PremLig = sh.Range("A2", sh.Range("A2").End(xlDown)).Rows.Count + 1 'Range("A65536").End(xlUp) 'Set rg2 = sh.Range(sh.Range("DV2").End(xlDown), sh.Range("DV2").End(xlDown)) DerLig2 = sh.Range("A2", sh.Range("A2").End(xlDown).Offset(1, 0)).Rows.Count + 1 MsgBox DerLig2 t = rg For i = PremLig To DerLig2 For j = 7 To 125 Cells(i, j) = Val(Cells(i, j)) Next j Next i rg = t fin: Set rg = Nothing Set sh = Nothing MsgBox "FIN" End Sub
La formule dans DV:
Le traitement est à appliquer si la cellule DV="FAUX" (je n'arrive jamais à faire comprendre à Excel que le résultat "" d'une cellule, dans mon esprit, revient à une cellule vide....)
Code : Sélectionner tout - Visualiser dans une fenêtre à part =SI(NBCAR(A2)=0;"";ESTNUM(G2:DU2))
Quelqu'un voit quelque chose?
Avec:
Sempiternel retour: Variable objet ou Bloc With non défini
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Dim rg As Range, rg2 As Range, cel As Range, sh As Worksheet, t() Dim i&, j& Set sh = Sheets("RECUP") Set rg = sh.Range(sh.Range("G" & Application.Rows.Count).End(xlUp), sh.Range("DU" & Application.Rows.Count).End(xlUp)) With Sheets("RECUP").Range("DV2:DV1000") PremLig = Range("DV2:DV1000").Find("FAUX", lookat:=xlWhole).Row MsgBox PremLig Set rg2 = sh.Range(sh.Range("DV2").End(xlDown), sh.Range("DV2").End(xlDown)) DerLig2 = sh.Range("A2", sh.Range("A2").End(xlDown).Offset(1, 0)).Rows.Count + 1 t = rg For i = PremLig To DerLig2 For j = 7 To 125 Cells(i, j) = Val(Cells(i, j)) Next j Next i rg = t fin: Set rg = Nothing Set sh = Nothing MsgBox "FIN" End With End Sub
Je m'arrache les cheveux
Ca avance:
Avec:
Retour:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Dim PremLig As Range, rg As Range, rg2 As Range, cel As Range, sh As Worksheet, t() Dim i&, j& Set sh = Sheets("RECUP") Set rg = sh.Range(sh.Range("G" & Application.Rows.Count).End(xlUp), sh.Range("DU" & Application.Rows.Count).End(xlUp)) With Sheets("RECUP").Range("DV2:DV1000") Set cel = Range("DV2:DV1000").Find("FAUX", lookat:=xlWhole) If cel Is Nothing Then MsgBox "code pas trouvé" Exit Sub PremLig = cel.Row MsgBox PremLig Set rg2 = sh.Range(sh.Range("DV2").End(xlDown), sh.Range("DV2").End(xlDown)) DerLig2 = sh.Range("A2", sh.Range("A2").End(xlDown).Offset(1, 0)).Rows.Count + 1 t = rg For i = PremLig To DerLig2 For j = 7 To 125 Cells(i, j) = Val(Cells(i, j)) Next j Next i rg = t fin: Set rg = Nothing Set sh = Nothing End If MsgBox "FIN" End With End Sub
"code pas trouvé"
Donc VBA ingore mes "FAUX"
Je ne vois absolument pas pourquoi????
Et pourtant quand je mets:
J'ai bien un faux qui s'affiche
Code : Sélectionner tout - Visualiser dans une fenêtre à part MsgBox Cells(i, 126).Value
Avec:
Le code commence à s'appliquer à DV2 et le traitement s'effectue sur toute les lignes sans tenir compte des "FAUX"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Sub COPYPASTESEL() Dim rg As Range, rg2 As Range, cel As Range, sh As Worksheet, t() Dim i&, j& Set sh = Sheets("RECUP") Set rg = sh.Range(sh.Range("G" & Application.Rows.Count).End(xlUp), sh.Range("DU" & Application.Rows.Count).End(xlUp)) With Sheets("RECUP").Range("DV2:DV1000") Cells(2, 126).Select Set cel = Cells.Find(What:="FAUX", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) If cel Is Nothing Then MsgBox "code pas trouvé" Exit Sub Else PremLig = cel.Row MsgBox PremLig For i = PremLig To DerLig2 For j = 7 To 125 Cells(i, j) = Val(Cells(i, j)) Next j Next i fin: Set rg = Nothing Set sh = Nothing End If MsgBox "FIN" End With End Sub
Rien ne sort de la brume pour vous?????
Il n'existe vraiment aucune solution pour qu'un code me renvoie le numéro de ligne d'une cellule dans laquelle FAUX s'incsrit suite à une formule =si(A2<>"";"FAUX";"")?
Partager