Dividere testo



  • Dividere testo
    di trump61 data: 09/02/2016 23:43:39

    Ciao, sto chiedendo l'aiuto del forum spesso utimamente, adesso ho questo problema e stavolta non ho idea se e come si possa fare, in pratica da questa stringa o altre simili devo dividere e collocare un numero per celle Dev.227-232-233-234-235-238-240
    tipo in A1 227 in A2 232, il probleme che alcune stinghe sono diverse da questa ad esempio Dev.53-101-23AB-102ABse qulche anima pia potesse almeno istradarmi gli sarei molto grato



  • di patel data: 10/02/2016 09:13:10

    visto che sei assiduo dovresti sapere che è meglio allegare un file di esempio con alcuni dati ed il risultato desiderato





  • di trump61 data: 10/02/2016 13:00:55

    Ciao, l'ho risolta così anche se ho dovuto terminare la stringa con un trattino . Non so se questo sia il modo migliore ma rispetto a ieri che non avevo idea di come fare è un buon passo avanti.
    Se hai un altro metodo è ben accetto, ho messo il file che comunque non è altro che una stringa su A2 e il codice
    Grazie
     
    Sub secondodev()
    Dim sh1 As Worksheet: Set sh1 = Worksheets("Foglio1")
    Dim X, Y, Z, M, N, W, L, H, J, K, T, E As String
    Dim S, D, R, Q, P, G, B, U, C, V, A As String
    Dim UU, CC, VV, AA, AQ, AC, AZ, AU As String
    M = sh1.Range("A2")
    W = "-"
    N = InStr(M, W)
    If N = 0 Then
    End
    Else
    X = Mid(sh1.Range("A2"), 5, N - 5)
    sh1.Range("D1").Value = X
    End If
    T = Len(sh1.Range("A2"))
    K = Mid(sh1.Range("A2"), N + 1, T)
    L = InStr(K, W)
    If L = 0 Then
    End
    Else
    H = Mid(sh1.Range("A2"), N + 1, L - 1)
    sh1.Range("E1").Value = H
    End If
    E = N + L
    S = Mid(sh1.Range("A2"), E + 1, T)
    D = InStr(S, W)
    If D = 0 Then
    End
    Else
    R = Mid(sh1.Range("A2"), E + 1, D - 1)
    sh1.Range("F1").Value = R
    End If
    G = E + D
    Q = Mid(sh1.Range("A2"), G + 1, T)
    B = InStr(Q, W)
    If B = 0 Then
    End
    Else
    P = Mid(sh1.Range("A2"), G + 1, B - 1)
    sh1.Range("G1").Value = P
    End If
    U = G + B
    V = Mid(sh1.Range("A2"), U + 1, T)
    C = InStr(V, W)
    If C = 0 Then
    End
    Else
    A = Mid(sh1.Range("A2"), U + 1, C - 1)
    sh1.Range("H1").Value = A
    End If
    UU = U + C
    VV = Mid(sh1.Range("A2"), UU + 1, T)
    CC = InStr(VV, W)
    If CC = 0 Then
    End
    Else
    AA = Mid(sh1.Range("A2"), UU + 1, CC - 1)
    sh1.Range("I1").Value = AA
    End If
    AU = UU + CC
    AC = Mid(sh1.Range("A2"), AU + 1, T)
    AQ = InStr(AC, W)
    If AQ = 0 Then
    End
    Else
    AZ = Mid(sh1.Range("A2"), AU + 1, AQ - 1)
    sh1.Range("J1").Value = AZ
    End If
    End Sub
    



  • di scossa data: 10/02/2016 13:36:11

    cit.: "Se hai un altro metodo è ben accetto"

    Sostituisci tutta quella filippica con il codice sottostante (scrive i valori sulla stessa riga della cella A selezionata)

    scossa's web site
    Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee.
    (George Bernard Shaw)

     
    Sub Estrai()
      Dim vArr As Variant
      Dim nCol As Long
      
      vArr = Split(Replace(ActiveCell.Value, "Dev.", ""), "-")
      For nCol = 0 To UBound(vArr)
        ActiveCell.Offset(0, 3 + nCol).Value = vArr(nCol)
      Next
    End Sub
    



  • di trump61 data: 10/02/2016 21:11:41

    Non l' ho ancora provato ma già mi piace molto.
    Grazie



  • di trump61 data: 11/02/2016 00:00:31

    Grazie scossa, non sapevo dell' esistenza della funzine Split