当前;y正在从用户表单中提取基于标准的数据(行),但是下面的代码只能在单个工作表上工作,当按钮在工作表上可用时,我可以让下面的代码工作,它会像预期的那样写入"Slave“工作表,但我终生无法获得正确编译的数组代码。
我从不同的地方尝试了不同的代码,包括这里,但我没有足够的能力调试这个错误。
有没有人能帮我一把,或者给我指个方向?
Sub CommandButton1_Click()
Dim strsearch As String, lastline As Integer, tocopy As Integer
strsearch = CStr(InputBox("enter the string to search for"))
'Enter code for all sheets in here...
lastline = Range("A65536").End(xlUp).Row
j = 1
For i = 1 To lastline
For Each c In Range("A" & i & ":Z" & i)
If InStr(c.Text, strsearch) Then
tocopy = 1
End If
Next c
If tocopy = 1 Then
Rows(i).Copy Destination:=Sheets("Slave").Rows(j)
j = j + 1
End If
tocopy = 0
Next i
End Sub发布于 2014-12-17 01:17:10
有更快的方法可以做到这一点,但这只是在表单循环中添加而已
Sub CommandButton1_Click()
Dim strsearch As String, lastline As Long
Dim sht as WorkSheet
strsearch = CStr(InputBox("enter the string to search for"))
j = 1
For Each sht in ThisWorkbook.WorkSheets
If sht.Name <> "Slave" Then
lastline = sht.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lastline
For Each c In sht.Range("A" & i & ":Z" & i)
If InStr(c.Text, strsearch) Then
sht.Rows(i).Copy Destination:=Sheets("Slave").Rows(j)
j = j + 1
Exit For 'stop looking!
End If
Next c
Next i
End If
Next sht
End Subhttps://stackoverflow.com/questions/27508694
复制相似问题