在单元格中找到单词

时间:2015-10-04 08:44:55

标签: excel vba excel-vba

Excel - VBA 我想知道如何使用VBA在Excel行范围内找到一个单词。防爆。 “要找到的词”,这不仅仅是单元格值,而是单词成为字符串。例如,在字符串“需要帮助映射网络打印机”中找到“网络”一词的方法。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="16dp">

    <com.devspark.robototextview.widget.RobotoTextView
        android:id="@+id/title"
        style="@style/text_subhead"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginBottom="@dimen/lessons_horizontal_margin_narrow"
        android:layout_marginLeft="@dimen/lessons_horizontal_margin_narrow"
        android:layout_marginRight="@dimen/lessons_horizontal_margin_narrow"
        android:layout_marginTop="@dimen/lessons_horizontal_margin_narrow"
        android:gravity="left"
        app:typeface="roboto_medium" />

    <com.devspark.robototextview.widget.RobotoTextView
        android:id="@+id/text"
        style="@style/text_subhead"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/lessons_horizontal_margin_narrow"
        android:layout_marginRight="@dimen/lessons_horizontal_margin_narrow"
        android:gravity="left"
        android:textColor="@color/text"
        app:typeface="roboto_regular" />

    <android.support.v7.widget.CardView
        android:id="@+id/image_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/lessons_horizontal_margin_narrow"
        app:cardCornerRadius="@dimen/lessons_image_card_corner_radius"
        app:cardElevation="3dp"
        app:cardPreventCornerOverlap="false"
        app:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <com.makeramen.roundedimageview.RoundedImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:contentDescription="@null"
                app:riv_corner_radius_top_left="@dimen/lessons_image_card_corner_radius"
                app:riv_corner_radius_top_right="@dimen/lessons_image_card_corner_radius" />

            <com.devspark.robototextview.widget.RobotoTextView
                android:id="@+id/caption"
                style="@style/text_caption"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/lessons_image_card_caption_margin"
                android:gravity="left"
                app:typeface="roboto_condensed_regular" />

        </LinearLayout>

    </android.support.v7.widget.CardView>

    <!-- Some other views that aren't particularly interesting -->

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

使用简单的循环

Sub Button1_Click()
    Dim ws As Worksheet
    Dim sh As Worksheet
    Dim lstRw As Long
    Dim rng As Range
    Dim s As String
    Dim c As Range

    s = "* network *"

    Set ws = Sheets("Data")
    Set sh = Sheets("SFB")

    With ws
        lstRw = .Cells(.Rows.Count, "E").End(xlUp).Row
        Set rng = .Range("E2:E" & lstRw)
    End With

    For Each c In rng.Cells
        If c.Value Like s Then
            c.EntireRow.Copy sh.Cells(sh.Rows.Count, "A").End(xlUp).Offset(1)
        End If
    Next c


End Sub

或者您可以使用过滤器宏

Sub FiltExample()
    Dim ws As Worksheet, sh As Worksheet
    Dim rws As Long, rng As Range
    Set ws = Sheets("Data")
    Set sh = Sheets("SFB")

    Application.ScreenUpdating = 0

    With ws
        rws = .Cells(.Rows.Count, "E").End(xlUp).Row
        .Range("E:E").AutoFilter Field:=1, Criteria1:="=*network*"
        Set rng = .Range("A2:Z" & rws).SpecialCells(xlCellTypeVisible)
        rng.EntireRow.Copy sh.Cells(sh.Rows.Count, "A").End(xlUp).Offset(1)
        .AutoFilterMode = False
    End With

End Sub