在列表中找到所有带有“数字”。“数字”的单元格,并将整行复制到其他位置

问题描述 投票:0回答:2

甚至感谢您对此内容的感谢;)因此,我试图在列表中找到几个单词都很好,但是现在我试图找到可能的日期,但是行不通。我尝试了所有可以考虑的问题..我没有意识形态。

这是我要使用的代码的一部分。

Option Compare Text

Sub Test()
Dim CL As Range

Dim POS As Long

For Each CL In Sheets(1).UsedRange.Columns(4).Cells
    POS = 0

    If InStr(1, CL.text, "test") > 0 Then POS = InStr(1, CL.text, "test")

    If InStr(1, CL.text, "example") > 0 Then POS = InStr(1, CL.text, "example")

     If InStr(1, CL.text, "[0-9].[0-9]") > 0 Then POS = InStr(1, CL.text, "[0-9].[0-9]")

    'i know the last IF is not ok ,but dont want to share my stupid rookie mistakes :)

    'its just to give the idea of what im looking for.

        If POS > 0 Then

    With CL.Characters.Font

      .FontStyle = "bold"

      .Color = -16383844

    End With

With CL.Interior

    .PatternColorIndex = xlAutomatic

    .Color = 13551615

    End With

      With CL.Select

      a = Worksheets("Data").Cells(Rows.Count, 8).End(xlUp).Row

                Intersect(ActiveCell.EntireRow, ActiveCell.CurrentRegion).Copy

          Worksheets("data").Cells(a + 1, 8).Select

    ActiveSheet.Paste

    End With  

End If

Next CL

End Sub

再次感谢您的时间。

excel vba search
2个回答
0
投票

考虑在此测试中使用Like运算符而不是InStr()

Sub dural()
    s = "kjhgf56yh8.9sdfgtyjn"
    MsgBox s Like "*#.#*"
End Sub

所以在您的代码中:

If CL.Text Like "*#.#*" Then POS = 1

这是作弊。您可以忽略它,因为不需要POS的实际值,只需要它大于零即可。

© www.soinside.com 2019 - 2024. All rights reserved.