Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Whatever I do I get the wrong result

There is a weak area in VBA Excel that is driving me crazy.!

The use of End(xlDown)

Even John Walkenbach states it clearly in his wonderful book.
"The use of End method may not produce the desired result..."

There is only one place ...here... that I feel confident that will
provide the answer..(Yes, I believe there must be a solution).

To state this challenge as clear as possible :

I have a column say B The column HAS blank cells

Column A Column B:

1 Blank
2 1
3 1
4 1
5 Blank
6 Blank
7 2
8 2
9 2
10 Blank
11 3
12 3
13 3


I need to get the ROW numbers for start and finish of group "1" etc

If the activecell is on cells(2,2) the cell value "1"

Range(activecell,activecell.End(xlDown).select

I get the address of the last "3" cells(13,2)

the "correct answer" should be cells(4,2).

I am sure you will come up of a way around it, but how one using the
END method come up with the code that will give reliable answer. and
while we are at it WHY we get wrong answer in the first place.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Whatever I do I get the wrong result

Hi Arishy,

Range(activecell,activecell.End(xlDown).select


Should read:

Range(ActiveCell, ActiveCell.End(xlDown)).Select

Note the second closing parenthesis.

Your experience is consistent with your 'blank' cells not being empty.
Perhaps these cells contain a formula which returns an empty string. If the
intervening cells are not empty, the your code will not produce the results
you expect, precisely as John Walkenbach explains.

Incidentally, if your intention is to select the last cell in the current
block, perhaps try:

ActiveCell.End(xlDown).Select


---
Regards,
Norman



"Arishy" wrote in message
ups.com...
There is a weak area in VBA Excel that is driving me crazy.!

The use of End(xlDown)

Even John Walkenbach states it clearly in his wonderful book.
"The use of End method may not produce the desired result..."

There is only one place ...here... that I feel confident that will
provide the answer..(Yes, I believe there must be a solution).

To state this challenge as clear as possible :

I have a column say B The column HAS blank cells

Column A Column B:

1 Blank
2 1
3 1
4 1
5 Blank
6 Blank
7 2
8 2
9 2
10 Blank
11 3
12 3
13 3


I need to get the ROW numbers for start and finish of group "1" etc

If the activecell is on cells(2,2) the cell value "1"

Range(activecell,activecell.End(xlDown).select

I get the address of the last "3" cells(13,2)

the "correct answer" should be cells(4,2).

I am sure you will come up of a way around it, but how one using the
END method come up with the code that will give reliable answer. and
while we are at it WHY we get wrong answer in the first place.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Whatever I do I get the wrong result

Hi Arishy,

The suggested use of

ActiveCell.End(xlDown).Select


referred to your described scenario.

If the active cell were blank, or the last populated cell in the current
block of column cells, the above instruction would select the first
subsequent populated cell, or the last cell in the column if the active cell
represented the last populated cell in the column.


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Arishy,

Range(activecell,activecell.End(xlDown).select


Should read:

Range(ActiveCell, ActiveCell.End(xlDown)).Select

Note the second closing parenthesis.

Your experience is consistent with your 'blank' cells not being empty.
Perhaps these cells contain a formula which returns an empty string. If
the intervening cells are not empty, the your code will not produce the
results you expect, precisely as John Walkenbach explains.

Incidentally, if your intention is to select the last cell in the current
block, perhaps try:

ActiveCell.End(xlDown).Select


---
Regards,
Norman



"Arishy" wrote in message
ups.com...
There is a weak area in VBA Excel that is driving me crazy.!

The use of End(xlDown)

Even John Walkenbach states it clearly in his wonderful book.
"The use of End method may not produce the desired result..."

There is only one place ...here... that I feel confident that will
provide the answer..(Yes, I believe there must be a solution).

To state this challenge as clear as possible :

I have a column say B The column HAS blank cells

Column A Column B:

1 Blank
2 1
3 1
4 1
5 Blank
6 Blank
7 2
8 2
9 2
10 Blank
11 3
12 3
13 3


I need to get the ROW numbers for start and finish of group "1" etc

If the activecell is on cells(2,2) the cell value "1"

Range(activecell,activecell.End(xlDown).select

I get the address of the last "3" cells(13,2)

the "correct answer" should be cells(4,2).

I am sure you will come up of a way around it, but how one using the
END method come up with the code that will give reliable answer. and
while we are at it WHY we get wrong answer in the first place.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Whatever I do I get the wrong result

and for the special case, if you want the cells containing numbers (stored
as numbers) and they are constants not formulas

Dim rng as Range
set rng = Columns(2).Specialcells(xlconstants,xlNumbers)
for each ar in rng.areas
msgbox ar.address
Next

adjust to fit your scenario

--
Regards,
Tom Ogilvy


"Norman Jones" wrote in message
...
Hi Arishy,

The suggested use of

ActiveCell.End(xlDown).Select


referred to your described scenario.

If the active cell were blank, or the last populated cell in the current
block of column cells, the above instruction would select the first
subsequent populated cell, or the last cell in the column if the active

cell
represented the last populated cell in the column.


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Arishy,

Range(activecell,activecell.End(xlDown).select


Should read:

Range(ActiveCell, ActiveCell.End(xlDown)).Select

Note the second closing parenthesis.

Your experience is consistent with your 'blank' cells not being empty.
Perhaps these cells contain a formula which returns an empty string. If
the intervening cells are not empty, the your code will not produce the
results you expect, precisely as John Walkenbach explains.

Incidentally, if your intention is to select the last cell in the

current
block, perhaps try:

ActiveCell.End(xlDown).Select


---
Regards,
Norman



"Arishy" wrote in message
ups.com...
There is a weak area in VBA Excel that is driving me crazy.!

The use of End(xlDown)

Even John Walkenbach states it clearly in his wonderful book.
"The use of End method may not produce the desired result..."

There is only one place ...here... that I feel confident that will
provide the answer..(Yes, I believe there must be a solution).

To state this challenge as clear as possible :

I have a column say B The column HAS blank cells

Column A Column B:

1 Blank
2 1
3 1
4 1
5 Blank
6 Blank
7 2
8 2
9 2
10 Blank
11 3
12 3
13 3


I need to get the ROW numbers for start and finish of group "1" etc

If the activecell is on cells(2,2) the cell value "1"

Range(activecell,activecell.End(xlDown).select

I get the address of the last "3" cells(13,2)

the "correct answer" should be cells(4,2).

I am sure you will come up of a way around it, but how one using the
END method come up with the code that will give reliable answer. and
while we are at it WHY we get wrong answer in the first place.







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Whatever I do I get the wrong result

Hi Norman,

Sorry about the typo...I am sure you knew it was NOT the problem.
As for the the error, for me to prove your point I had to make the cell
really Blank. Then it worked. That applied to all my trials So, thank
you for pointing out the reason. Now for the solution; I was pretty
sure I never put any formula or "anything" in the blank cells to be
detected. But I do remember that the first time I used the code it
worked then it did not; so I presume the balnk cells got "corrupted"
for unknown reason. In the real world this will happen I am sure ..so
here is my question to you:

How do I avoid this from happenning Do I go before applying the macro,
and check that every blank cell is really blank ( catch 22)
There must be a better way.!!!!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Whatever I do I get the wrong result

My very dear Tom

What a solution... WoW....You opened a new world for me by your simple
yet elegant proceedure.
I will build my solution based on your routine. Thank you again for
sharing your valuable knowledge and I do hope I pay back this wonderful
forum.

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
Wrong Result with an IF function Thij_rahya Excel Worksheet Functions 6 July 23rd 09 09:29 PM
excel result return wrong calcuation result garyww Excel Worksheet Functions 1 August 14th 06 11:14 AM
excel result return wrong calcuation result garyww Excel Worksheet Functions 0 August 14th 06 05:02 AM
excel result return wrong calcuation result garyww Excel Worksheet Functions 0 August 14th 06 05:02 AM
SUM returns wrong result MarkN Excel Worksheet Functions 5 October 20th 05 03:59 AM


All times are GMT +1. The time now is 03:42 AM.

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"