I have a problem with my code. In short, I want to go through some tables which are filled with formulas and have the code do a hard copy of the day specified by the HelpDay variable.
Dim countTab As Long
Dim HelpDay As Date
Dim i As Long
------------------------------------------------------
Sub DailyData()
Application.ScreenUpdating = False
Sheets("Input").Select
countTab = Range("D34").Value 'sets the amount of loops
HelpDay = Range("D5").Value 'sets the day
Sheets("InputData").Select
Range("A1").Select
For i = 0 To countTab
Cells.Find(What:=HelpDay, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 3).Activate
Range(ActiveCell, ActiveCell.Offset(0, 19)).Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next
Sheets("Input").Select
MsgBox "All daily data saved in the tables. In case of incorrect entry, either open the old version and start again or adjust manually in the tables."
End Sub
When I try to run this code i get a "Runtime Error 91" and the debugger shows the cells.find as the problem.
However, if i add
MsgBox "Tables copied: " & i
just at the end of the loop suddendly the runtime error doesn´t appear anymore (but now i have to click the Ok-Button after each loop).
I already checked the formatting of all effected cells and tried some of the solutions in other threads but I cant get the code to work properly.
Please let me know if you have an idea for me to try.
Cheers