我找不到我的問題的解決方案,希望您在這里提供幫助。
在 A 列中,每個單元格中都有不同的文本。在單元格內的文本之間,有一個特定結構的數字 - “####.##.####”
我想復制這個數字(如果存在)并將其復制到同一行的 B 列。*如果同一單元格中有多個具有上述結構的數字,則應將下一個數字復制到同一行的C、D、E等列。

Sub findValues()
Dim loopCounter, lastRow, nextBlank As Long
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For loopCounter = 1 To lastRow Step 1
With Sheets("Sheet2")
nextBlank = .Range("A" & Rows.Count).End(xlUp).Offset(1).Row
If Cells(loopCounter, 1).Value Like "[0-9]{4}.[0-9]{2}.[0-9]{4}" Then
Cells(loopCounter, 2) = 1
End If
End With
Next loopCounter
End Sub
uj5u.com熱心網友回復:
拆分列(回圈)
Option Explicit
Sub SplitColumnA()
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet2")
Dim lRow As Long: lRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Dim cCell As Range
Dim Words() As String
Dim Sentence As String
Dim r As Long, c As Long, n As Long
For r = 2 To lRow
Set cCell = ws.Cells(r, "A")
Sentence = Replace(CStr(cCell.Value), ")", "")
Words = Split(Sentence)
For n = 0 To UBound(Words)
If Words(n) Like "####.##.####" Then
c = c 1
cCell.Offset(, c).Value = Words(n)
End If
Next n
c = 0
Next r
MsgBox "Data split.", vbInformation
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/451399.html
上一篇:計算列中的連續數字
