比如输出的BOM,或者元器件标准化界面中有这样一行

 

C2,C4,C6,C8,C12,C14,C17,C20,C21,C22,C23,C26,C28,C29,C32,C34,C36,C38,C39,C421,C433

自动转化为:

C2   , C4   , C6   , C8   , C12 ,

C14 , C17 , C20 , C21 , C22 ,

C23 , C26 , C28 , C29 , C32 ,

C34 , C36 , C38 , C39 , C421,

C433

 

BOM中5个位号一行,其他具体看实际效果

 

以下VBA参考自GPT


Sub TransformSpecificText()
    Dim cellText As String
    Dim transformedText As String
    Dim lines As Variant
    Dim line As Variant
    Dim i As Long, j As Long
    Dim maxLength As Long
    
    ' Specify the cell text
    cellText = "C1, C233, C2344, C344"
    
    ' Split the cell contents into lines
    lines = Split(cellText, ", ")
    
    ' Find the maximum length of the items
    For i = 1 To UBound(lines)
        line = lines(i)
        If Len(line) > maxLength Then
            maxLength = Len(line)
        End If
    Next i
    
    ' Transform each line with aligned items
    For i = 1 To UBound(lines)
        line = lines(i)
        transformedText = transformedText & line & Space(maxLength - Len(line) + 2)
        
        If i Mod 5 = 0 Then
            transformedText = transformedText & vbCrLf
        Else
            transformedText = transformedText & ","
        End If
    Next i
    
    ' Display the transformed text
    MsgBox transformedText
End Sub

\n#原理图设计#
#原理图设计#
嘉立创EDA

还没有评论,抢个沙发!