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

如何用vba对e x ce l工作表中所有含有某符号单元格的内容提取放置到新的工作表中。
原表中含有某符号单元格可能在不同列中,但放置在新表中的同一列。
如果:原表中同一行,有两列包含符号“!”,则放在新表中同一行相邻的两列。
bavca 1年前 已收到1个回答 举报

寻找师傅 幼苗

共回答了20个问题采纳率:80% 举报

假设原表范围为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

1年前

10
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 2.162 s. - webmaster@yulucn.com