Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default range addressing var issue

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default range addressing var issue

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default range addressing var issue

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default range addressing var issue

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default range addressing var issue

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA and range addressing C Brandt Excel Discussion (Misc queries) 3 July 31st 07 04:38 PM
VBA Range Addressing in For Loop Stephen William Foyle Excel Programming 2 March 2nd 07 05:33 PM
Range Issue Arturo Excel Programming 4 February 5th 07 10:57 PM
how do i maintain named range addressing after deleting row? erp Excel Programming 0 December 1st 05 01:52 AM
indirect addressing? a range of cells spindle Excel Programming 2 December 7th 04 07:19 AM


All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"