Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 431
- Office Version
- 365
- Platform
- Windows
- Mobile
This code fills down to last row in sheet rather then stopping at the specified LRow?
VBA Code:
Sub FillDates()
Dim wb As Workbook
Dim ws As Worksheet
Dim Holws As Worksheet
Dim FCell As Range
Dim LRow As Long, lngNoDays As Long
Set wb = Workbooks("DailyMail.xlsx")
Set ws = wb.Worksheets("Daily Mail Update")
Set Holws = wb.Worksheets("HolidaysYr")
LRow = ws.Range("D" & Rows.Count).End(xlUp).Row
Set FCell = ws.Range("A2")
If Date = Application.WorkDay(DateSerial(Year(Date), Month(Date), 0), 1) Or _
Date = Application.WorkDay(DateSerial(Year(Date), Month(Date), 0), 2) Or _
Date = Application.WorkDay(DateSerial(Year(Date), Month(Date), 0), 3) Or _
Date = Application.WorkDay(DateSerial(Year(Date), Month(Date), 0), 4) Then
With FCell
.Value = FirstWorkDayOfMonth(Date, Holws.Range("A2:A" & LRow))
.NumberFormat = ("dd/mm/yyyy")
.HorizontalAlignment = xlCenter
End With
ws.Range("C2:C" & LRow).Clear
With ws
lngNoDays = .Range("A2").Value
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("A2").AutoFill Destination:=.Range("A2:A" & LRow).Resize(lngNoDays), Type:=xlFillWeekdays
End With
End If
Set wb = Nothing
Set ws = Nothing
Set FCell = Nothing
End Sub