Formule Hexadecimal a 4 chiffres

Bonjour, dans mon sub, je voudrais que l'addition suivante sache qu'elle traite des cellules Hexadecimal:

Cells(i, 2).Value = Cells(i - 1, 2).Value + x . Quel serait la syntaxe? J'aimerais egalement que le resultat comporte toujours 4 chiffres.

Sub ADRESSES2()  
Dim lg As Long, i&, a&, x&, mem&
    lg = Range("I" & Rows.Count).End(xlUp).Row
    Columns(2).NumberFormat = "0000"
    For i = 2 To lg
    If Cells(i, 9) Like ".ORG*" Then Cells(i, 2) = Mid(Cells(i, 9), 6, 4): GoTo 1
        For a = 3 To 6
            If Cells(i - 1, a) <> "" Then x = x + 1
        Next a

        Cells(i, 2).Value = Cells(i - 1, 2).Value + x
1       Cells(i, 2) = "'" & Cells(i, 2).Text
        x = 0
    Next i
    Cells(2, 2) = ""

    End Sub

bonjour,

à tester

Sub ADRESSES2()
    Dim lg As Long, i&, a&, x&, mem&
    lg = Range("I" & Rows.Count).End(xlUp).Row
    For i = 2 To lg
        If Cells(i, 9) Like ".ORG*" Then
            Cells(i, 2) = Mid(Cells(i, 9), 6, 4)
        Else
            For a = 3 To 6
                If Cells(i - 1, a) <> "" Then x = x + 1
            Next a

            Cells(i, 2) = Val("&H" & Cells(i - 1, 2)) + x
        End If
        Cells(i, 2) = "'" & Right("0000" + Hex(Cells(i, 2)), 4)
        x = 0
    Next i
    Cells(2, 2) = ""
End Sub

salut! ca ne compte pas comme je voudrais: si je veux additionner 3 a la valeur de la cellule par exemple 8, il faudrais que ca me donne 0B et non 11.

Sub ADRESSES2()
        Dim lg As Long, i&, a&, x&, mem&
        lg = Range("I" & Rows.Count).End(xlUp).Row
        For i = 2 To lg
            If Cells(i, 9) Like ".ORG*" Then
                Cells(i, 2) = Mid(Cells(i, 9), 6, 4)
            Else
                For a = 3 To 6
                    If Cells(i - 1, a) <> "" Then x = x + 1
                Next a

                Cells(i, 2) = Val("&H" & Cells(i - 1, 2)) + x
            End If
            Cells(i, 2) = "'" & Right("0000" + Hex(Cells(i, 2)), 4)
            x = 0
        Next i
        Cells(2, 2) = ""
    End Sub

il me semble que c'est que fait le code que j'ai fourni.

ceci fait le calcul en décimal

Cells(i, 2) = Val("&H" & Cells(i - 1, 2)) + x

si cells(i-1,2)=8 et x =3 alors cells(i,2)=11

ceci convertit le résultat décimal en hexadecimal

 Cells(i, 2) = "'" & Right("0000" + Hex(Cells(i, 2)), 4)

si cells(i,2)=11 alors cells(i,2)=000B

H2so4, tu avais raison. Ca fonctionne tres bien!

Merci a toi.

Rechercher des sujets similaires à "formule hexadecimal chiffres"