OVH Cloud OVH Cloud

Macro : destination cellule avant

2 réponses
Avatar
Françoise
Bonjour à tous,

je fais une macro dans laquelle je veux dire :
si dans cellule de la colonne C, existe "SDF"
alors écrit dans la cellule B correspondante : "OK"
sinon
laisser le contenu de la cellule B tel qu'il est
voici ma macro
-----
Dim rng As Range
Dim c As Range
Dim b As Range

With Worksheets("Plan de montage")
Set b = Range("B1:B" & [B65536].End(xlUp).Row)
'Set c = Range("C1:C" & [C65536].End(xlUp).Row)
Set rng = Range("C1:C" & [C65536].End(xlUp).Row)
End With

For Each c In rng
If UCase(c.Value) = "SDF" Then
b = "OK"
ElseIf UCase(c.Value) <> "SDF" Then
b = b
End If
Next
Set rng = Nothing
-----
Je n'arrive pas à obtenir le résultat voulu
Où est l'erreur ?

D'avance merci pour votre aide

2 réponses

Avatar
anonymousA
bonjour,

For Each c In rng
If UCase(c.Value) = "SDF" Then c.offset(0,-1).value = "OK"
Next
Set rng = Nothing

A+


Bonjour à tous,

je fais une macro dans laquelle je veux dire :
si dans cellule de la colonne C, existe "SDF"
alors écrit dans la cellule B correspondante : "OK"
sinon
laisser le contenu de la cellule B tel qu'il est
voici ma macro
-----
Dim rng As Range
Dim c As Range
Dim b As Range

With Worksheets("Plan de montage")
Set b = Range("B1:B" & [B65536].End(xlUp).Row)
'Set c = Range("C1:C" & [C65536].End(xlUp).Row)
Set rng = Range("C1:C" & [C65536].End(xlUp).Row)
End With

For Each c In rng
If UCase(c.Value) = "SDF" Then
b = "OK"
ElseIf UCase(c.Value) <> "SDF" Then
b = b
End If
Next
Set rng = Nothing
-----
Je n'arrive pas à obtenir le résultat voulu
Où est l'erreur ?

D'avance merci pour votre aide



Avatar
ChrisV
Bonjour Françoise,

Sub zaza()
Dim i As Long
Application.ScreenUpdating = False
For i = 1 To [C65536].End(xlUp).Row
If Cells(i, 3) Like "*SDF*" Then
Cells(i, 2) = "Ok"
End If
Next i
End Sub


ChrisV


"Françoise" a écrit dans le message de
news:
Bonjour à tous,

je fais une macro dans laquelle je veux dire :
si dans cellule de la colonne C, existe "SDF"
alors écrit dans la cellule B correspondante : "OK"
sinon
laisser le contenu de la cellule B tel qu'il est
voici ma macro
-----
Dim rng As Range
Dim c As Range
Dim b As Range

With Worksheets("Plan de montage")
Set b = Range("B1:B" & [B65536].End(xlUp).Row)
'Set c = Range("C1:C" & [C65536].End(xlUp).Row)
Set rng = Range("C1:C" & [C65536].End(xlUp).Row)
End With

For Each c In rng
If UCase(c.Value) = "SDF" Then
b = "OK"
ElseIf UCase(c.Value) <> "SDF" Then
b = b
End If
Next
Set rng = Nothing
-----
Je n'arrive pas à obtenir le résultat voulu
Où est l'erreur ?

D'avance merci pour votre aide