i have this code that looks at every sheet start with the name "week".
if in that sheet there's the word "fod" it copys the date of the day in that week.
i run the code by button and if if there's 1 week (week1) and the word "fod" is in it's working fine.
but if there's more than 1 week (week2, week3... etc) it works for the last week and doesnt show nothing about the weeks before.
i think the problem is with the for loop. how can i solve this?
Public Sub fodfunc()
Dim Wb As Workbook
Dim s As Worksheet
Set s = Sheets(Sheets.Count)
Dim sht As Worksheet
Dim FindRow As Range
Dim FindRowNumber As Long
Set Wb = ActiveWorkbook
If Not StrComp("Week", Left(s.Name, 4), vbTextCompare) = 0 Then
MsgBox "no" & Left(s.Name, 4)
Else
For Each sht In ActiveWorkbook.Worksheets
With Wb.Sheets(s.Name)
Set FindRow = .Range("M:M").Find(What:="fod", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
End With
result = Right(s.Name, Len(s.Name) - 4)
result = CInt(result)
If Not FindRow Is Nothing Then
FindRowNumber = FindRow.Row
Range(Cells(result+ 1, result).Address & ":" & Cells(result + 2, result).Address).Select
ActiveCell.Value = ThisWorkbook.Sheets(s.Name).Range("c2")
Range(Cells(result , result).Address & ":" & Cells(result + 1, result).Address).Select
ActiveCell.Value = s.Name
Else
MsgBox "no fod has been done in that week"
End If
Exit For
Next sht
End If
End Sub
thanks!
Bookmarks