Hello Everyone!
The code below is attempting to go through every sheet we have in this workbook and copy any column that matches the "FindString" piece.
This code works perfectly when all of the sheets matches what the FindString piece is, but I noticed that if a worksheet does not match with "FindString" then it would go back and loop to the previous sheets. It wouldn't go to the Next available WS for a while. I cannot seem to find the reason why it is doing that.
Any help is appreciated!
The code below is attempting to go through every sheet we have in this workbook and copy any column that matches the "FindString" piece.
This code works perfectly when all of the sheets matches what the FindString piece is, but I noticed that if a worksheet does not match with "FindString" then it would go back and loop to the previous sheets. It wouldn't go to the Next available WS for a while. I cannot seem to find the reason why it is doing that.
Any help is appreciated!
VBA Code:
Sub TakeInfoFromMonthsTest()
Dim FindString As String
Dim Rng As Range
Dim WS As Worksheet
Dim SizeFit As Long
FindString = InputBox("Enter a Search value")
SizeFit = InputBox("How many rows would you like to copy")
For Each WS In ThisWorkbook.Sheets
If WS.Name <> "Holder" And WS.Name <> "Macros" Then
With WS.Range("A:GY")
Set Rng = .Find(What:=FindString, _
After:=.Range("N32"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
Sheets("Holder").Range("A1").End(xlToRight).Offset(0, 1) = "Nothing"
End If
End With
Selection.Resize(SizeFit).Copy
Sheets("Holder").Range("A1").End(xlToRight).Offset(0, 1).PasteSpecial Paste:=xlPasteValues
End If
Next WS
End Sub