Link to home
Start Free TrialLog in
Avatar of newparadigmz
newparadigmzFlag for United States of America

asked on

Excel 2007 VBA, debugging range/array

For the following code;

    Set rStartCell = ThisWorkbook.ActiveSheet.Range("A3")
    Set rPathList = Range(rStartCell.Offset(0, 0), rStartCell.End(xlDown).Offset(0, 2))
    iRows = rPathList.Rows.Count
    iCols = rPathList.Columns.Count
    ReDim avPaths(iRows, iCols)
    avPaths = rPathList.Value

The range is n rows by 3 columns
This works as expected when n rows > 1
But when n rows is actually just 1 (because I'm deleteing all the data), iRows always = 4

Anyone see why?
Avatar of newparadigmz
newparadigmz
Flag of United States of America image

ASKER

OK, so I can see now that it's because

If the range is > 1, rStartCell.End(xlDown), crawls down the range, BUT if range =1, rStartCell.End(xlDown) jumps to the next cell with data and counts everything in between (above it)

How do I prevent this so that if the range is 1 row, it equals 1 row, and not go to the next cell with data?
Avatar of aikimark
Please post a sample workbook with the data where this fails.
SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
forgot about CurrentRegion