Schrodinger Code - XLOOKUP

Duncaroos

New Member
Joined
May 2, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have a sheet where I have a custom formula that is used for a graphical schedule on an Output sheet in excel. The function outputs the Date that is closest to the "MilestoneDate" input, but also places a physical marker/shape in the correct location on the sheet containing the schedule. I am having an issue with the line highlighted below in bold text (ONLY when there is a code break before this line); I get Excel VBA Error 424 "Object Required". If I do not have any breaks before this line, the function works fine.

I only can get XLOOKUP to work when MilestoneDate and TempOut are set as RANGE data type. Graph_Dates shows its output like this Graph_Dates Snapshot, which maybe(?) is part of the problem, but I don't get why if I do not watch before this problematic line the function behaves normally. I put it I have made a grave mistake somewhere that I am not seeing.

Rich (BB code):
Function Milestone(WBS As String, MilestoneDate As Range, ShowMarker As Range, TaskID As Long, Grph_Dates As Range, Grph_UIDs As Range, Watch_TaskColors As Range) As Variant

    Milestone = ""  'Default Output
   
    'Define Task Table (For Marker Generation)
        Dim TTbl As ListObject
        Dim Ind_Tsk As Long
       
        Set TTbl = DataSheet.ListObjects("DataTable_Tasks")
        Ind_Tsk = TTbl.ListColumns("Task").Index
   
    'Define Variables for Date & Cell Targeting
        Dim TempOut As Range                                       'Temporary storage of function output
        Dim UID As String                                                 'Unique Identifer for Row search
        Dim col As Long                                                    'column # for shape location
        Dim row As Long                                                   'row # for shape location
        Dim Trgt As Range                                                 'Target Cell for shape location
   
    'Do Stuff
        On Error GoTo skip
            If WBS <> "" And MilestoneDate <> "" And ShowMarker.Value = True Then
               
                With WorksheetFunction
                    Set TempOut = .XLookup(MilestoneDate, Grph_Dates, Grph_Dates, , 1)                      'Find relevant date on graph for location {{{Excel VBA Error 424 when in debug}}}
                   
                    If Not (IsEmpty(TempOut)) And Err = 0 Then                                              'If no error (date found) - Find Cell Address
                        Milestone = TempOut
                       
                        'Unique ID for finding correct Graph Row to Assign Marker:
                        UID = WBS & "_" & .XLookup(TaskID, _
                                                   TTbl.ListColumns(1).DataBodyRange, _
                                                   TTbl.ListColumns(Ind_Tsk).DataBodyRange, _
                                                   , 0)
                       
                        col = .Match(TempOut, Grph_Dates, 0) + 8                                    'Cell Column #
                        row = .Match(UID, Grph_UIDs, 0) + 3                                             'Cell Row #
                        Set Trgt = OutputSheet.Cells(row, col)                                           'Set Target Cell
   
                        'Call DrawMilestone(WBS, TaskID, ShowMarker, Trgt, TTbl)
                       
                    Else
                   
                        GoTo DMS
                       
                    End If
                   
                End With
               
            Else
           
DMS:            If WBS <> "" Then Call DeleteMilestone(WBS, ShowMarker, TTbl)
               
            End If

skip:
    Call InvalidMilestone
   
    'Call EnableWorkbook

I do have some global variables at the top of the module:
VBA Code:
Option Explicit
Global TempCalcCode As Long


TIA
 
Last edited by a moderator:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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