Object required error

Object required error

Hi,

I am getting an 'Object required' error on the line

Call HideColumnsOutsideRange(ws, startOfWeek, endOfWeek) 

when I run the ShowCurrentWeek macro but not when I run the ShowCurrentMonth macro. 

Any ideas?

Regards,
GW

Option Explicit

Sub HideColumnsOutsideRange(ws as Worksheet, startDate As Date, endDate As Date)
    Dim lastCol As Long
    Dim c As Long
    Dim hdr As Variant
    Dim dt As Date

    ' Find last used column in row 1
    Application.ScreenUpdating = False

    ws.Cells.EntireColumn.Hidden = False
    
    lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column

    For c = 1 To lastCol
        hdr = ws.Cells(1, c).Value

        If IsDate(hdr) Then
            ' Normalize to pure date (drop time / timezone artifacts)
            dt = DateSerial(Year(CDate(hdr)), Month(CDate(hdr)), Day(CDate(hdr)))
            ' Debug.print "dt: " & dt & " start: " & startDate & " end: " & endDate
            ' Hide if outside the given range
            If (dt < startDate) Or (dt > endDate) Then
                ws.Columns(c).Hidden = True
            End If
        Else
            ws.Columns(c).Hidden = True
        End If
    Next c

    Application.ScreenUpdating = True
End Sub

Sub ShowCurrentMonth()
    Dim ws As Worksheet
    Dim today As Date, startOfMonth As Date, endOfMonth As Date

    Set ws = ActiveSheet
    today = DateValue(Now)

    startOfMonth = DateSerial(Year(today), Month(today), 1)
    endOfMonth   = DateSerial(Year(today), Month(today) + 1, 0)

    Call HideColumnsOutsideRange(ws, startOfMonth, endOfMonth)
End Sub

Sub ShowCurrentWeek()
    Dim ws As Worksheet
    Dim today As Date, startOfWeek As Date, endOfWeek As Date

    Set ws = ActiveSheet
    today = DateValue(Now)

    startOfWeek = today - (Weekday(today) - 1)  ' Sunday–Saturday
    'Debug.Print "startOfWeek: " & startOfWeek
    endOfWeek = startOfWeek + 6

    Call HideColumnsOutsideRange(ws, startOfWeek, endOfWeek)
End Sub
    • Sticky Posts

    • What's new in Zoho Sheet: Simplify data entry and collaboration

      Hello, Zoho Sheet community! Last year, our team was focused on research and development so we could deliver updates that enhance your spreadsheet experience. This year, we’re excited to deliver those enhancements—but we'll be rolling them out incrementally
    • Introducing Forms in Zoho Sheet

      We hereby bring you the power of ​forms in Zoho Sheet. ​Now, build and create your own customized forms using Zoho Sheet. Be it compiling a questionnaire or rolling out a survey, Zoho Sheet can do it all for you. Forms is an excellent feature that helps you collect information in the simplest of ways and having it in Zoho Sheet takes it a notch higher. Build Simple yet Powerful forms Building forms using Zoho Sheet is fairly simple. The exclusive 'Form' tab lets you create one quickly. Whether you
    • Slicers are now available in Zoho Sheet—filter your data interactively

      At Zoho Sheet, we diligently track user requests and feedback. In line with this, based on extensive user requests, we've integrated Slicers to pivot tables and are delighted to announce its release. Slicers are interactive visual filters that have add,
    • Introducing Data Bars: Graphically represent changes in data within the cells

      Conditional formatting has helped millions of spreadsheet users analyze and highlight their data more efficiently. In addition to the classic rules, color scales, and icon sets available in Zoho Sheet, you can now apply Data Bars, a convenient method
    • Feature enhancement: Highlight rows based on a cell value

      Hello Sheet users, We're excited to announce a new feature enhacement, shaped directly by your valuable feedback! As you might know, conditional formatting is a great tool for anyone dealing with large data sets. Previously, if you’ve ever wanted to draw