Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the following code that crashes:
' Note ActiveCell is set in Column "B" and lastrow in column +1 For z = 1 to 26 ActiveCell.value = Application.WorksheetFunction.CountBlank( _ Range(Cells(z + 1, 2), Cells(z + 1, lastrow_in_col))) ActiveCell.Offset(0, 1).Select ' move right by one col Next z Where lastrow_in_col = 3005 column range begins at "B" and ends at "AA" My range address is wrong |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It *looks* like you have the arguments to the Cells property backwards. The
first argument is the row number whereas the second argument is the column number. So the Range property that you are feeding the CountBlank should be this... Range(Cells(2, z + 1), Cells(lastrow_in_col, z + 1)) By the way, unless you are hiding information from us, the last line inside the loop (where you do the Select operation) is not needed as the loop is moving through the cells via code and there is no need to select anything in order for it to to that. -- Rick (MVP - Excel) "miek" wrote in message ... I have the following code that crashes: ' Note ActiveCell is set in Column "B" and lastrow in column +1 For z = 1 to 26 ActiveCell.value = Application.WorksheetFunction.CountBlank( _ Range(Cells(z + 1, 2), Cells(z + 1, lastrow_in_col))) ActiveCell.Offset(0, 1).Select ' move right by one col Next z Where lastrow_in_col = 3005 column range begins at "B" and ends at "AA" My range address is wrong |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for you help.
"Rick Rothstein" wrote: It *looks* like you have the arguments to the Cells property backwards. The first argument is the row number whereas the second argument is the column number. So the Range property that you are feeding the CountBlank should be this... Range(Cells(2, z + 1), Cells(lastrow_in_col, z + 1)) By the way, unless you are hiding information from us, the last line inside the loop (where you do the Select operation) is not needed as the loop is moving through the cells via code and there is no need to select anything in order for it to to that. -- Rick (MVP - Excel) "miek" wrote in message ... I have the following code that crashes: ' Note ActiveCell is set in Column "B" and lastrow in column +1 For z = 1 to 26 ActiveCell.value = Application.WorksheetFunction.CountBlank( _ Range(Cells(z + 1, 2), Cells(z + 1, lastrow_in_col))) ActiveCell.Offset(0, 1).Select ' move right by one col Next z Where lastrow_in_col = 3005 column range begins at "B" and ends at "AA" My range address is wrong |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Your first range is (column2, Row2), (Column3005, Row2). Is that what you
want? Unless you have xl2007, it won't work. The way your code is written, you are advancing 25 rows in your For ... Next statement and 25 columns to the right with your offset statement.. If you are using xl2007, there is nothing to cause the crash. xl2003 and older has 256 columns max, so the 3005 would cause an error. "miek" wrote in message ... I have the following code that crashes: ' Note ActiveCell is set in Column "B" and lastrow in column +1 For z = 1 to 26 ActiveCell.value = Application.WorksheetFunction.CountBlank( _ Range(Cells(z + 1, 2), Cells(z + 1, lastrow_in_col))) ActiveCell.Offset(0, 1).Select ' move right by one col Next z Where lastrow_in_col = 3005 column range begins at "B" and ends at "AA" My range address is wrong |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thnaks for your help
"JLGWhiz" wrote: Your first range is (column2, Row2), (Column3005, Row2). Is that what you want? Unless you have xl2007, it won't work. The way your code is written, you are advancing 25 rows in your For ... Next statement and 25 columns to the right with your offset statement.. If you are using xl2007, there is nothing to cause the crash. xl2003 and older has 256 columns max, so the 3005 would cause an error. "miek" wrote in message ... I have the following code that crashes: ' Note ActiveCell is set in Column "B" and lastrow in column +1 For z = 1 to 26 ActiveCell.value = Application.WorksheetFunction.CountBlank( _ Range(Cells(z + 1, 2), Cells(z + 1, lastrow_in_col))) ActiveCell.Offset(0, 1).Select ' move right by one col Next z Where lastrow_in_col = 3005 column range begins at "B" and ends at "AA" My range address is wrong |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VBA and range addressing | Excel Discussion (Misc queries) | |||
VBA Range Addressing in For Loop | Excel Programming | |||
Range Issue | Excel Programming | |||
how do i maintain named range addressing after deleting row? | Excel Programming | |||
indirect addressing? a range of cells | Excel Programming |