+ Reply to Thread
Results 1 to 14 of 14

Problem will CELLS(Row,Col).Value when accessing dates

  1. #1
    Registered User
    Join Date
    07-18-2012
    Location
    Rotherham, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Post Problem will CELLS(Row,Col).Value when accessing dates

    I'm using the following VBA statement as part of a routine to copy Sales Invoice info to another sheet in Excel 2003:

    Sheets("Unpaid").Cells(UnpaidRow, 11).Value = _
    Sheets(2).Cells(SalesRow, 49).Value

    The value being copied to Sheet(2) is a date.

    The statement works fine providing the date being copied is less or equal to the current date. If the date is in advance of the current date then I get "Error 13 - type mismatch"

    I've no idea why this doesn't work as the cells in question both contain valid date values.

    Any help would be welcome.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    I can't see how you would get a type mismatch error from that. Do you have any change event code in sheets(2) that might be being triggered?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    Hi bluesplayer43,

    Welcome to the forum!!

    I'd say that either the UnpaidRow and/or the SalesRow variables are being assigned as strings which the code cannot use as it needs a positive whole number to work with. Have you declared them as any particular type?

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    07-18-2012
    Location
    Rotherham, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    Both are declaired as Integers:

    Dim SalesRow As Integer
    Dim UnpaidRow As Integer

  5. #5
    Registered User
    Join Date
    07-18-2012
    Location
    Rotherham, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    Quote Originally Posted by romperstomper View Post
    I can't see how you would get a type mismatch error from that. Do you have any change event code in sheets(2) that might be being triggered?
    No nothing; but it only generates an error when the date is greater than the current date, so I dn't see how any change would effect that?

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    It would depend on what the event code did.

    So you're saying that if you run the code with all cells having dates less than today, it works but if you change a date to a date after today, it fails on that cell? If so, can you post a sample of the workbook?

  7. #7
    Registered User
    Join Date
    07-18-2012
    Location
    Rotherham, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    Quote Originally Posted by romperstomper View Post
    It would depend on what the event code did.

    So you're saying that if you run the code with all cells having dates less than today, it works but if you change a date to a date after today, it fails on that cell? If so, can you post a sample of the workbook?

    Thats correct, the routine runs fine if all the dates are equal or less than the current date. If I increment the date to a future date I get the error 13 with the above code highlighted in the VBA code window.

    I can't really post the whole spreadsheet as it's quite large and has our companies sales info. However, the whole routine is below:


    Sub FindUnpaidInvoices()

    ' Search for Unpaid invoices

    Dim SalesRow As Integer
    Dim UnpaidRow As Integer
    Dim RowCounter As Integer
    Dim MaxInvoices As Integer
    Dim InvoiceEntered As Boolean
    Dim IsUnpaid As Boolean

    Application.ScreenUpdating = False

    ' Clear Existing Data
    Sheets("Unpaid").Range("C20").Select
    Range("UnpaidTable").ClearContents
    Range("C20").Select

    ' Set start values
    SalesRow = 11
    UnpaidRow = 20
    MaxInvoices = Range("Total_Invoices").Value

    For i = 1 To MaxInvoices
    InvoiceEntered = IsDate(Sheets(2).Cells(SalesRow, 3))
    IsUnpaid = Not (IsDate(Sheets(2).Cells(SalesRow, 27)))

    ' MsgBox InvoiceEntered & "" & IsUnpaid & " " & SalesRow & " - " & Sheets(2).Cells(SalesRow, 27)

    If InvoiceEntered And IsUnpaid Then

    ' Invoice Date
    Sheets("Unpaid").Cells(UnpaidRow, 3).Value = _
    Sheets(2).Cells(SalesRow, 20).Value
    ' Account Number
    Sheets("Unpaid").Cells(UnpaidRow, 4).Value = _
    Sheets(2).Cells(SalesRow, 21).Value
    ' Client Name
    Sheets("Unpaid").Cells(UnpaidRow, 5).Value = _
    Sheets(2).Cells(SalesRow, 22).Value
    ' Invoice Number
    Sheets("Unpaid").Cells(UnpaidRow, 6).Value = _
    Sheets(2).Cells(SalesRow, 23).Value
    ' Invoice Month
    Sheets("Unpaid").Cells(UnpaidRow, 7).Value = _
    Sheets(2).Cells(SalesRow, 24).Value
    ' VAT
    Sheets("Unpaid").Cells(UnpaidRow, 8).Value = _
    Sheets(2).Cells(SalesRow, 11).Value
    ' WHT
    Sheets("Unpaid").Cells(UnpaidRow, 9).Value = _
    Sheets(2).Cells(SalesRow, 12).Value
    ' Amount Due
    Sheets("Unpaid").Cells(UnpaidRow, 10).Value = _
    Sheets(2).Cells(SalesRow, 14).Value
    ' Days over due (Total Days less 30)
    Sheets("Unpaid").Cells(UnpaidRow, 11).Value = _
    Sheets(2).Cells(SalesRow, 49).Value - 30

    UnpaidRow = UnpaidRow + 1

    End If

    SalesRow = SalesRow + 1
    Next i

    Application.ScreenUpdating = True

    End Sub

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    We don't need any info other than the dates and the two sheets in question. There's nothing inherently wrong with the code (though you should use Long rather than Integer for row variables as a rule) as far as I can see.

  9. #9
    Registered User
    Join Date
    07-18-2012
    Location
    Rotherham, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    If I change any of the dates to a future date, it generates the error 13, no matter their position. If I set the date back to the current date or less the routine completes succesfully. All the date cells in the column refernced are correctly formatted as dates and contain date values.

    I've tried debugging it and it always halts at the future date, no matter where in the column of dates that is.

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    What's in cell AW15 of the second tab i.e. Sheet(2)?

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    There is nothing inherently wrong with the code, as I mentioned (I've just run it), so I think it has something to do with your workbook, which is why I asked to see it.

  12. #12
    Registered User
    Join Date
    07-18-2012
    Location
    Rotherham, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    Thanks I think you've spotted my problem.

    AW15 is the number of days from when an invoice has been issued. It's calculated by a formula and I've just noticed when an advance date is enetered it generates a #NUM error, hence the failure of my routine.

    I need to correct my formulae.

    Many thanks for all your help .. everybody !

    It's much appreciated.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    Ahh - you didn't have the - 30 in your original posted code!

  14. #14
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Problem will CELLS(Row,Col).Value when accessing dates

    Thanks for the feedback and I'm glad we got it sorted in the end

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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