I have the current code and it works as i need it to. The problem is it takes quite a while to run through due to the for loop. The variable x ranges from 300 to about 8000. I am attempting to add in code to hide unimportant dates based on when a client pays. I need to include all dates rather than just generate a weekly/fortnightly/monthly calendar as other events occur on those dates. I will be adding a hide/unhide code for the other event dates as well but at the moment im wondering if it is possible to speed up this code.
Sub Client_Payments()
Application.ScreenUpdating = False
Dim first As Integer
Dim x As Integer
Dim n As Integer
Dim ws1 As Worksheet
Set ws1 = Sheets("Payment_Summary")
first = Application.Match(Range("Next_Payment").Value2, ws1.Range("A:A"), 0)
x = ThisWorkbook.Sheets("Payment_Summary").Range("Duration").Value2 + 7
ThisWorkbook.Sheets("Payment_Summary").Range(Cells(7, 1), Cells(x, 1)).EntireRow.Hidden = True
If ThisWorkbook.Sheets("Client_Details").Range("Freq").Value = "Weekly" Then
For n = 0 To x / 7
ws1.Cells(first + (n * 7), 2).EntireRow.Hidden = False
Next
End If
If ThisWorkbook.Sheets("Client_Details").Range("freq").Value = "Fortnightly" Then
For n = 0 To x / 14
ws1.Cells(first + (n * 14), 2).EntireRow.Hidden = False
Next
End If
If ThisWorkbook.Sheets("Client_Details").Range("freq").Value = "Monthly" Then
For n = 0 To x / 30
If Day(ws1.Cells(n + first, 1).Value) = Day(ThisWorkbook.Sheets("Client_Details").Range("Next_payment").Value) Then
ws1.Cells(n + first, 1).EntireRow.Hidden = False
End If
Next
End If
End Sub