Consulting

Results 1 to 5 of 5

Thread: Formula won't work past a certain date

  1. #1
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    3
    Location

    Formula won't work past a certain date

    Hi All,

    Please help I have no idea of what is going wrong.

    I have the following formula which is working fine up to and including week 26 but then when I put the next end week date (For week 27) in the formula isn't working - won't bring over the text in the specified cell range?? If I go back to week 26 still works like a dream!

    I have the following;

    Sheet 1: Date formula in cell G4 of =WEEKNUM(G3,2) this refers to the cell G3 where I manually enter the week ending date.

    This formula is working still returning the appropriate end product after week 26

    I then in cell A69 have the formula =LOOKUPCONCATENATE(G4,A68) where A68 = "Summary of Incidents"

    This formula has worked perfectly up to the end of week 26 and now it won't work?

    For the formula in cell A69 I have a VBA module that is as follows;

    Public Function LookUpConcatenate(InputDate As Range, Header As Range) As String
    
    Dim wsData As Worksheet
    Dim TempText As String
    Dim DatePointer As Integer, ColumnHeader As Integer, Counter As Integer, ControlCounter As Integer, Instances As Integer
    
    Set wsData = Worksheets("DATASHEET")
    DatePointer = WorksheetFunction.Match(InputDate, wsData.Range("A:A"), 0)
    ColumnHeader = WorksheetFunction.Match(Header, wsData.Range("2:2"), 0)
    Instances = WorksheetFunction.CountIf(wsData.Range("A:A"), DatePointer)
    ControlCounter = (DatePointer + Instances) - 1
    
    For Counter = DatePointer To ControlCounter
    TempText = wsData.Cells(Counter, ColumnHeader).Value
    If TempText <> "" Then
    If LookUpConcatenate <> "" Then
    LookUpConcatenate = LookUpConcatenate & Chr(12) & TempText
    Else
    LookUpConcatenate = TempText
    End If
    End If
    Next Counter
    
    End Function
    Please help!!
    Last edited by Bob Phillips; 07-07-2014 at 07:48 AM. Reason: Added VBA tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    There is more data involved here, Datasheet. Can you post the work book, it is hard to set it all up?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    3
    Location
    Hi

    here is a copy of the workbook as requested.

    Thanks
    Attached Files Attached Files

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think you were wrongly calculating Instances

    Public Function LookUpConcatenate(InputDate As Range, Header As Range) As String
    Dim wsData As Worksheet
    Dim TempText As String
    Dim DatePointer As Integer, ColumnHeader As Integer, Counter As Integer, ControlCounter As Integer, Instances As Integer
    
        Set wsData = Worksheets("DATASHEET")
        DatePointer = WorksheetFunction.Match(InputDate, wsData.Range("A:A"), 0)
        ColumnHeader = WorksheetFunction.Match(Header, wsData.Range("2:2"), 0)
        Instances = WorksheetFunction.CountIf(wsData.Range("A:A"), InputDate)
        ControlCounter = (DatePointer + Instances) - 1
        
        For Counter = DatePointer To ControlCounter
            TempText = wsData.Cells(Counter, ColumnHeader).Value
            If TempText <> "" Then
                If LookUpConcatenate <> "" Then
                LookUpConcatenate = LookUpConcatenate & Chr(12) & TempText
                Else
                LookUpConcatenate = TempText
                End If
            End If
        Next Counter
    End Function
    But you still have a problem. G4 is a week number, but that weeknumber can apply to 2014 and 2015 and so on, so Instances counts more that the weeknum for the given date.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    3
    Location
    Thank you !! Brilliant it works now !

Tags for this Thread

Posting Permissions

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