Hi All,
I am receiving a compile error “Next without For” for a loop I am trying tocreate.
I need the codeto loop through all the spreadsheets in a workbook, search for the word investigate in column W,if found copy cell A2 and paste the value into Column B in the “Master” spreadsheetin descending order.
If “investigate”is not found ignore and move onto the next sheet.
Below is the codeI have so far.
Any help isgreatly appreciated
I am receiving a compile error “Next without For” for a loop I am trying tocreate.
I need the codeto loop through all the spreadsheets in a workbook, search for the word investigate in column W,if found copy cell A2 and paste the value into Column B in the “Master” spreadsheetin descending order.
If “investigate”is not found ignore and move onto the next sheet.
Below is the codeI have so far.
Any help isgreatly appreciated
Code:
Sub CombineData3()
Dim Sht As Worksheet
For Each Sht In ActiveWorkbook.Worksheets
If Sht.name <> "Master" Then
Sht.Select
Dim foundsomething As Range
Dim searchterm As String
searchterm = "Investigate"
On Error Resume Next
ActiveSheet.ShowAllData
Columns("A:W").Select
Selection.EntireColumn.Hidden = False
Set foundsomething = Application.ActiveSheet.Find(What:="Investigate", After:=ActiveCell, lookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If (Not foundsomething Is Nothing) And columnW = "Investigate" Then
Range("A2").Copy
Worksheets("Master").Activate
Range("B1" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Else
Sht.Select
Next Sht
End If
End Sub
Last edited by a moderator: