Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Leona Wright   on Jan 03 In MS Office Category.

  
Question Answered By: Damon Perez   on Jan 03

one more comment on the last cell  question. Actually Excel is also treating
cells which are deleted with DEL key or ClearContent as part of its data  range.
This may You can explore the data range with the UsedRange command.

Example:
FRow = ActiveSheet.UsedRange.Row
FCol = ActiveSheet.UsedRange.Column
LRow = FRow + ActiveSheet.UsedRange.Rows.Count - 1
LCol = FCol + ActiveSheet.UsedRange.Columns.Count - 1

FRow gives you the first row, FCol the first column. It may be that your used
range does not start in row 1 and or column  1. That's why I use the formula for
LRow and LCol to adjust that.

As said, when deleting some rows or columns, you still may see the last cell
outside of your range. I normally use the command line
FRow = ActiveSheet.UsedRange.Row
even if I don't need it to adjusts the UsedRange to deleted rows/columns.

I'm not sure if you also want to delete  the empty  lines in A115 etc. if so, here
is some code  you could use:
FRow = ActiveSheet.UsedRange.Row
Row = FRow
While Row < FRow + ActiveSheet.UsedRange.Rows.Count - 1
If Application.WorksheetFunction.CountBlank(Rows(Row)) = 256 Then
Rows(Row).EntireRow.Delete
n = ActiveSheet.UsedRange.Rows.Count
Else
Row = Row + 1
End If
Wend

This code also works if your table does not start in row 1. I use FRow +
ActiveSheet.UsedRange.Rows.Count - 1 in the While command line, because this
re-adjusts the data range whenever deleting a row. Thus, I do not have to loop
through a fixed length of a table. Please note that this routine takes long time
if you have a large table. You may want to disable screen updating.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Some Questions from Beginner Or get search suggestion and latest updates.


Tagged: