.End(xlUp) not working for some cases in Excel/VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • billelev
    New Member
    • Nov 2006
    • 119

    .End(xlUp) not working for some cases in Excel/VBA

    I am using the following code to find the last row that contains data, within a particular column on a spreadsheet.

    Code:
    Dim ws As Worksheet
    Set ws = Worksheets(Me.ChartDataSheetName)
    GetLastRowWithData = ws.Cells(ws.Rows.Count, dataCol).End(xlUp).row
    It works for columns that contain only numbers. However, for cells that contain formulas, I get the following message:

    Code:
    Run Time Error 13
    Type Mismatch
    This is independent of the declared type of GetLastRowWithD ata (i.e. I get the message whether it is Integer or Long). Note that it works with columns containing numbers.

    Any suggestions as to why this might not be working would be appreciated!
Working...