Avatar of newparadigmz
Flag 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?
VB ScriptMicrosoft Excel

Avatar of undefined
Last Comment

8/22/2022 - Mon

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?

Please post a sample workbook with the data where this fails.
Robberbaron (robr)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

forgot about CurrentRegion
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck