ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   vba searching for strings in multiple worksheets (https://www.excelbanter.com/excel-discussion-misc-queries/101421-vba-searching-strings-multiple-worksheets.html)

[email protected]

vba searching for strings in multiple worksheets
 
Hi,

I am trying to search multiple worksheets for the word "Fail" and then
copy all of the "fail" data that has a failure into another worksheet.
I am able to copy one sheet to another, but cannot figure out how to
search multiple sheets.

The number of worksheets are dynamic. The user can add sheets to the
workbook.

Here is my working code for one sheet:

With Sheet2
For i = 1 To .UsedRange.Rows.Count

If .Cells(i, 1) = "Fail" Then

'Offset to select the testcase number
Sheet1.Cells(j, 3) = Sheet2.Cells(i, 2)

'Offset to select the Serial Number
Sheet1.Cells(j, 2) = Sheet2.Cells(i, 4)

j = j + 1

Else
Sheet1.range("B15:c500") = ""

End If
Next
End With

Thank you


Dave Peterson

vba searching for strings in multiple worksheets
 
Maybe...

dim wks as worksheet
for each wks in activeworkbook.worksheets
if lcase(wks.codename) = lcase("sheet1") then
'skip this sheet
else
With wks
For i = 1 To .UsedRange.Rows.Count
If .Cells(i, 1) = "Fail" Then
'Offset to select the testcase number
Sheet1.Cells(j, 3) = .Cells(i, 2)

'Offset to select the Serial Number
Sheet1.Cells(j, 2) = .Cells(i, 4)

j = j + 1

Else
'still want to do this???
Sheet1.range("B15:c500") = ""
End If
Next i
End With
end if
next wks

(untested, uncompiled. Watch for typos!)

wrote:

Hi,

I am trying to search multiple worksheets for the word "Fail" and then
copy all of the "fail" data that has a failure into another worksheet.
I am able to copy one sheet to another, but cannot figure out how to
search multiple sheets.

The number of worksheets are dynamic. The user can add sheets to the
workbook.

Here is my working code for one sheet:

With Sheet2
For i = 1 To .UsedRange.Rows.Count

If .Cells(i, 1) = "Fail" Then

'Offset to select the testcase number
Sheet1.Cells(j, 3) = Sheet2.Cells(i, 2)

'Offset to select the Serial Number
Sheet1.Cells(j, 2) = Sheet2.Cells(i, 4)

j = j + 1

Else
Sheet1.range("B15:c500") = ""

End If
Next
End With

Thank you


--

Dave Peterson

jetted

vba searching for strings in multiple worksheets
 

Hi Justin

See attached document
every "Fail" should be stored in worksheet "Fail_Workbook"

Thanks
Denis


+-------------------------------------------------------------------+
|Filename: Book2.zip |
|Download: http://www.excelforum.com/attachment.php?postid=5108 |
+-------------------------------------------------------------------+

--
jetted
------------------------------------------------------------------------
jetted's Profile: http://www.excelforum.com/member.php...o&userid=17532
View this thread: http://www.excelforum.com/showthread...hreadid=565152



All times are GMT +1. The time now is 08:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com