Retrieve the value of a cell
Solved
nihadlahit
-
NLAH Posted messages 135 Status Membre -
NLAH Posted messages 135 Status Membre -
```vba
Sub MaMacro()
Dim x As Integer, celfind As Range, lig As Integer, col As Integer, m As Range
Dim val As Variant
With Worksheets("Feuil3").Range("B2:B100")
x = InputBox("saisir le numéro de la commande")
Set celfind = .Find(x)
If Not celfind Is Nothing Then
lig = celfind.Row
val = Worksheets("Feuil3").Cells(lig, "C").Value
Worksheets("Feuil1").Range("A1:D3").Copy
Worksheets("Feuil2").Range("A1:D3").PasteSpecial Paste:=xlPasteAll
Set m = Worksheets("Feuil2").Rows(1).Find(x)
If Not m Is Nothing Then
col = m.Column
Worksheets("Feuil2").Cells(3, col).Value = val
End If
Else
MsgBox "Valeur non trouvée."
End If
End With
End Sub
```
Sub MaMacro()
Dim x As Integer, celfind As Range, lig As Integer, col As Integer, m As Range
Dim val As Variant
With Worksheets("Feuil3").Range("B2:B100")
x = InputBox("saisir le numéro de la commande")
Set celfind = .Find(x)
If Not celfind Is Nothing Then
lig = celfind.Row
val = Worksheets("Feuil3").Cells(lig, "C").Value
Worksheets("Feuil1").Range("A1:D3").Copy
Worksheets("Feuil2").Range("A1:D3").PasteSpecial Paste:=xlPasteAll
Set m = Worksheets("Feuil2").Rows(1).Find(x)
If Not m Is Nothing Then
col = m.Column
Worksheets("Feuil2").Cells(3, col).Value = val
End If
Else
MsgBox "Valeur non trouvée."
End If
End With
End Sub
```
1 réponse
Hello,
When you use code, please use the codes because it's more readable.
Your corrected macro:
--
Always zen
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupéry
When you use code, please use the codes because it's more readable.
Your corrected macro:
Dim x As Variant, celfind As Range, lig As Integer, col As Integer, m As Range With Worksheets("Feuil3").Range("B1:B100") x = InputBox("enter the order number") Set celfind = .Find(x) lig = celfind.Row With Worksheets("feuil1").Range("A1:D3") .Copy Destination:=Worksheets("feuil2").Range("A1") End With Set m = Worksheets("feuil2").Rows("1").Find(celfind) col = m.Column Worksheets("feuil2").Cells(3, col).Value = Worksheets("feuil3").Cells(lig, 3).Value End With --
Always zen
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupéry
Thank you so much
It works very well