venerdì 25 ottobre 2013

m ricostruzione articolo

Attribute VB_Name = "m_ricostruzione_articolo"

'

Option Explicit

'

'

Dim restituito

'

' vba === ricostruzione articolo originario

' per abbinamento

' articolo cliente: EA0115

' articolo fornitore: EA 011 5

'

Sub ScansionaArticoli()

Dim quanterighe, contarighe, foglio, colonnadaleggere, contenuto

Set foglio = Sheets(ActiveSheet.Name)

'

quanterighe = Range(foglio.UsedRange.Cells(foglio.UsedRange.Rows.Count, 1).Address).Row

contarighe = 2

colonnadaleggere = "k"

'

While contarighe < quanterighe

contenuto = Trim(foglio.Cells(contarighe, colonnadaleggere).Value)

If Len(contenuto) = 6 Then

Call aritcoloanalizza(contenuto, "(\S)", 6)

foglio.Cells(contarighe, colonnadaleggere).Value = restituito

End If

contarighe = contarighe + 1

Wend

'

'

End Sub

'

Sub aritcoloanalizza(contenuto, cosatrovare, lunghezzarichiesta)

Dim oggRegEx, myMatches, myMatch

Set oggRegEx = CreateObject("VBScript.RegExp")

'

oggRegEx.Global = True

oggRegEx.Pattern = cosatrovare

Set myMatches = oggRegEx.Execute(contenuto)

'

If myMatches.Count = lunghezzarichiesta Then

restituito = ""

restituito = restituito & myMatches(0).Value

restituito = restituito & myMatches(1).Value

restituito = restituito & " "

restituito = restituito & myMatches(2).Value

restituito = restituito & myMatches(3).Value

restituito = restituito & myMatches(4).Value

restituito = restituito & " "

restituito = restituito & myMatches(5).Value

End If

'

'

End Sub

Nessun commento:

Posta un commento