我有一张excel表格,我想根据它们的值选择一些单元格,然后使用VBA将这些单元格复制到另一张表格。
我有一大堆代码遍历所有excel表格并搜索特定值然后返回此单元格的总数。
样本数据
Private Sub CommandButton1_Click()
row_number = 4
count_of_str = 0
Do
DoEvents
row_number = row_number + 1
item_in_review = Sheets("Sheet1").Range("H" & row_number)
If InStr(item_in_review, "name") Then
count_of_str = count_of_str + 1
End If
Loop Until item_in_review = ""
MsgBox "the str occured: " & count_of_str & " times."
End Sub
答案 0 :(得分:0)
未测试:
Private Sub CommandButton1_Click()
Dim count_of_str As Long
Dim c as Range, d As Range
count_of_str = 0
Set c = Sheets("Sheet1").Range("H4") 'cell to check
Set d = Sheets("Sheet2").Range("A2") 'destination to copy to
Do While Len(c.Value) > 0
If InStr(c.Value, "name") > 0 Then
count_of_str = count_of_str + 1
c.Copy d
Set d = d.Offset(1, 0) 'next destination row
End If
Set c = c.Offset(1, 0) 'next cell to check
Loop
MsgBox "the str occured: " & count_of_str & " times."
End Sub
答案 1 :(得分:0)
利用Key Password
/ Find
方法
我们还不完全清楚您的数据所在的列。我假设标签FindNext
和name
位于contact
,而实际数据位于{{1} }}
此外,我假设每个H
都有一个I
,并且没有包含任何检查。
name