Excel.Application.Cells.SpecialCells(xlCellTypeLastCell) returning bottom of worksheet, not last data cell

后端 未结 3 1808
迷失自我
迷失自我 2020-12-06 15:13

I\'m writing a method in VBA in Excel 2013 to loop through the rows in two worksheets and compare the text in a column from each. When I run my code, I find that the code lo

3条回答
  •  感动是毒
    2020-12-06 15:55

    You can try this:

    Dim xlastcel As Range  
    On Error Resume Next  
       ActiveSheet.ShowAllData: Err.Clear  ' Show All  
       ActiveSheet.UsedRange               ' Ajust Vertical Scrool  
       With ActiveSheet:  Set xlastcell = .Cells.Find(What:="*", After:=.[A1], SearchDirection:=xlPrevious): End With  
       If Err.Number > 0 Then MsgBox "Sheet without data", vbOKOnly  
    On Error GoTo 0  
    

提交回复
热议问题