+ Reply to Thread
Results 1 to 6 of 6

Make a Date variable equal a single-cell array formula

  1. #1
    Registered User
    Join Date
    03-06-2012
    Location
    Johanesburg, South Africa
    MS-Off Ver
    2010: Excel, Access, Word, PowerPoint, Outlook
    Posts
    3

    Question Make a Date variable equal a single-cell array formula

    Hi,

    I have a working single-cell array formula in cell G18: {=MAX(IF(F21=DOA_ApprovalType,DOA_EffectiveDate))}

    Capture.PNG

    I am creating a sub to read in an ApprovalType (replacing F21 above). I want to use the above formula in vba to get the single date result which i want to store in a date variable to pass on to a user defined function. I can't get the above function to calc or store except to write the formula on an sheet which then calculates.
    Any ideas to get it to work without going to the sheet will be much appreciated.

    I have being trying for hour but don't know enough to get it to work.

    Regards,
    Shamala

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Make a Date variable = single-cell array formula

    Use Application.Evaluate.

  3. #3
    Registered User
    Join Date
    03-06-2012
    Location
    Johanesburg, South Africa
    MS-Off Ver
    2010: Excel, Access, Word, PowerPoint, Outlook
    Posts
    3

    Re: Make a Date variable = single-cell array formula

    Thanks that seems to work but i must be applying it incorrectly because i get a Type mismatch error on the same line:

    Sub FindDOA()

    Dim r As Integer
    Dim s As String
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
    Dim ApprovalType As String
    Dim ETC As Integer
    Dim TempDate As Date

    r = ActiveCell.Row
    s = Range("a" & r).Value

    ' Promt
    strPrompt = "Are you sure you want to re/calculate the DOA for file " & s & "?"

    ' Dialog's Title
    strTitle = "Be carefull not to override DOA requirements, especially when the" & vbCr & "DOA Policy has changed."

    'Display MessageBox
    iRet = MsgBox(strPrompt, vbOKCancel, strTitle)

    ' Check pressed button
    If iRet = vbCancel Then
    MsgBox "Cancelled."
    Else
    'get ApprovalType and ETC
    ApprovalType = Range("c" & r).Value
    ETC = Range("h" & r).Value

    TempDate = Application.Evaluate("={MAX(IF(ApprovalType=DOA_ApprovalType,DOA_EffectiveDate))}")

    MsgBox "Yes!"
    End If



    End Sub

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Make a Date variable = single-cell array formula

    Remove the curly brackets, these are added by Excel on the spreadsheet.

  5. #5
    Registered User
    Join Date
    03-06-2012
    Location
    Johanesburg, South Africa
    MS-Off Ver
    2010: Excel, Access, Word, PowerPoint, Outlook
    Posts
    3

    Re: Make a Date variable = single-cell array formula

    Thanks Bob.

    I took out the curly brackets and still got the error (it was partly the problem), then in addition i took out the "Dim TempDate As Date". Now i get TempDate = Error 2029.

    I also tried: Dim TempDate As Variant - still got the same error.

    Could it be something to do with the named range "DOA_EffectiveDate" which is formatted as a date? Any suggestion on this?
    Last edited by Shamala; 03-07-2012 at 01:02 PM.

  6. #6
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Make a Date variable = single-cell array formula

    Try this

    Please Login or Register  to view this content.

+ 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