Here's the exact definition of UsedRange
(MSDN reference) :
Every Worksheet object has a UsedRange property that returns a Range object representing the area of a worksheet that is being used. The UsedRange property represents the area described by the farthest upper-left and farthest lower-right nonempty cells in a worksheet and includes all cells in between.
So basically, what that line does is :
.UsedRange
-> "Draws" a box around the outer-most cells with content inside.
.Columns
-> Selects the entire columns of those cells
.Count
-> Returns an integer corresponding to how many columns there are (in this selection)
- 8
-> Subtracts 8 from the previous integer.
I assume VBA calculates the UsedRange by finding the non-empty cells with lowest and highest index values.
Most likely, you're getting an error because the number of lines in your range is smaller than 3, and therefore the number returned is negative.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…