如何用vba对e x ce l工作表中所有含有某符号单元格的内容提取放置到新的工作表中。

1个回答

  • 假设原表范围为A1至Z100,新表表名为Sheet2,程序:

    Sub FindString()

    Dim i As Integer, j As Integer, iNew As Integer, jNew As Integer

    Dim IsWrite As Boolean

    iNew = 1: jNew = 1 '指定新表中的写入起始行及列

    For i = 1 To 100 '指定原表中的搜索行

    For j = 1 To 26 '指定原表中的搜索列

    If InStr(1, Cells(i, j), "!", vbTextCompare) > 0 Then '逐个单元格搜索指定的字符

    Sheets(2).Cells(iNew, jNew) = Cells(i, j) '写入新表

    jNew = jNew + 1

    IsWrite = True

    End If

    Next j

    If IsWrite = True Then

    iNew = iNew + 1

    IsWrite = False

    End If

    Next i

    End Su