简体   繁体   中英

VBA auto select last filled cell

I have an excel sheet with data. I have some VBA that will filter the sheet to a specific value and then move down to the last filled cell.

    ActiveSheet.Range("$S$2:$S$1218").AutoFilter Field:=1, Criteria1:= _
    "Scheduled"
ActiveSheet.Cells(ActiveSheet.Rows.Count, Selection.Column).End(xlUp).Select

This works fine for the purpose. However, column A has numbers filled out past where I want it to stop. Could this be edited to only query column F (for example) and move down to the last filled cell in column F.

Thank you!

In vba coding, cells are typically denoted as cells(i,j) where i represents the number of row while j represents the number of column.

Since you want to work on column F, which is column no 6, you just have to change the code accordingly like this:

ActiveSheet.Cells(ActiveSheet.Rows.Count, 6).End(xlUp).Select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM