+ Reply to Thread
Results 1 to 5 of 5

Subtraction using WorksheetFunction.WorkDay results in mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    05-07-2013
    Location
    CZ, EU
    MS-Off Ver
    2010/2016
    Posts
    31

    Subtraction using WorksheetFunction.WorkDay results in mismatch

    Hello anybody,

    following piece of code results in "Type mismatch" error:

    ...
    
    Dim CellRng As Range
    
    ...
    
        For Each cell In CellRng
            If (WorksheetFunction.WorkDay(Date, 1, ThisWorkbook.Worksheets("2-KALENDÁŘ A SVÁTKY").Range("D3:D42")) - cell.Value > 0) And (cell.Value <> "") And (cell.Offset(0, -4) <> "a") Then
                IsMsgYel = True
                CellDateF = Format(cell, "dd.mm.yyyy")
                MsgYel = MsgYel & CellDateF & " - " & cell.Offset(0, 1).Value & " (" & cell.Offset(0, 2).Value & ")" & Date & vbCrLf
            End If
        Next
    
    ...
    The cells in range contain dates, I know that WorksheetFunction.WorkDay returns "double"... I tried some conversions (cell.Value to double, WorksheetFunction.WorkDay to date), but no success.

    Thanks for any help.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Subtraction using WorksheetFunction.WorkDay results in mismatch

    can you attach, its a little unclear

  3. #3
    Registered User
    Join Date
    05-07-2013
    Location
    CZ, EU
    MS-Off Ver
    2010/2016
    Posts
    31

    Re: Subtraction using WorksheetFunction.WorkDay results in mismatch

    Hello,

    lots of code inside the workbook, which I'm not allowed to send... but simpler version of my question:

    In this simpler version of my code I'm testing cells (in some range) containing dates, whether the cell date is before the next workday.

    Dim CellRng as Range
    ...
    
    For Each cell In CellRng
        If WorksheetFunction.WorkDay(Date, 1) - cell.Value > 0 Then
    ...

    This subtraction results in type mismatch...

  4. #4
    Registered User
    Join Date
    05-07-2013
    Location
    CZ, EU
    MS-Off Ver
    2010/2016
    Posts
    31

    Re: Subtraction using WorksheetFunction.WorkDay results in mismatch

    Problem is in the "0" - there were also some variables and calculation before on the right side, so now I can change it to

    If WorksheetFunction.WorkDay(Date, 1) > cell.Value Then

    ...

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Subtraction using WorksheetFunction.WorkDay results in mismatch

    Oh, ok.
    
    If isdate(cell.value) then
    
     if cell.value < WorksheetFunction.WorkDay(Date, 1)  then
    
                       HERE
    
    else
    end if 
    
    else
    end if

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1