This Code fills in below current month.

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
431
Office Version
  1. 365
Platform
  1. Windows
  2. 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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Why are you using Resize in there as well?
 
Upvote 0
Solution

Forum statistics

Threads
1,223,880
Messages
6,175,154
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top