在Excel单元格字符串中的某些字符之间读取

时间:2020-11-06 18:13:07

标签: vba excel-formula

使用Excel在VBA上的新工作。独自学习并为这个社区感到高兴。

我正在努力从excel单元格中的字符串中提取信息。

示例: 单元格值:Make.Model.Issuer

我正在尝试使用“。”读取任何字符集。作为极限。 从右读到“。” 在“。”之间阅读。 从左读到“。”

提前谢谢大家:)

2 个答案:

答案 0 :(得分:0)

我不确定您对提取的字符串的处理方式,因此将其放入单元格中。

这将遍历A列,并将拆分后的字符串放入同一行中所需的任意列中。

    Dim strarr As Variant
    Dim i As Long
    Dim lr As Long
    Dim j As Long
    With Sheet1 'Change as needed
        lr = .Cells(.Rows.Count, 1).End(xlUp).Row 'Change the 1 to whatever your column is
        For i = 1 To lr
            strarr = Split(.Cells(i, 1).Value, ".") 'Change the 1 to whatever your column is
            For j = LBound(strarr) To UBound(strarr)
                .Cells(i, 1).Offset(, j + 1).Value = strarr(j)
            Next j
        Next i
    End With

答案 1 :(得分:0)

以下代码将生成一个带有所选单词的数组:

Dim s As String
Dim a As Variant
   
s = "Make.Model.Issuer"
a = Split(s, ".")
MsgBox a(0) & "   " & a(1) & "   " & a(2)