Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default check cell contents

I need some help with a loop I want to check a range of cells and select only
the cells with a valid product in them for example i want to copy ice cream
but ignore any cells that have nothing in them or have the word product in
them I am trying to use the loop below

If Cells(x, 1).Text < "Product" And _
Cells(x, 1).Text < "" Then
d = x - 1

unfortunately it would appear that the text formatting in each cell hase a
bearing for example product will be selected if the font colour is say blue.
is there anyway around this
--
Jack
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default check cell contents

Try using .Value instead of .Text
--
- K Dales


"Jack" wrote:

I need some help with a loop I want to check a range of cells and select only
the cells with a valid product in them for example i want to copy ice cream
but ignore any cells that have nothing in them or have the word product in
them I am trying to use the loop below

If Cells(x, 1).Text < "Product" And _
Cells(x, 1).Text < "" Then
d = x - 1

unfortunately it would appear that the text formatting in each cell hase a
bearing for example product will be selected if the font colour is say blue.
is there anyway around this
--
Jack

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default check cell contents

I have tried value it will not work either the the and in the loop should
have been an or but no matter what I try it still will not work.
--
Jack

"K Dales" wrote:

Try using .Value instead of .Text
--
- K Dales


"Jack" wrote:

I need some help with a loop I want to check a range of cells and select only
the cells with a valid product in them for example i want to copy ice cream
but ignore any cells that have nothing in them or have the word product in
them I am trying to use the loop below

If Cells(x, 1).Text < "Product" And _
Cells(x, 1).Text < "" Then
d = x - 1

unfortunately it would appear that the text formatting in each cell hase a
bearing for example product will be selected if the font colour is say blue.
is there anyway around this
--
Jack

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default check cell contents

The format should not matter. Are the words (e.g. "Product") typed in to the
cells or are they the result of some formula? Regardless, there are a couple
potential problems when trying to test text: first, upper vs. lower case;
e.g. "product" < "Product". Then, sometimes there are spaces typed before
or after the word that are hard to find just by looking, but "Product " <
"Product". These are especially problems if users are typing the values; it
is easy for someone to put a space after the word and not even be aware of it.

This would deal with both of those issues:
If Trim(Ucase(Cells(x,1).Value))<"PRODUCT" Then...

If this does not do it then you may have a problem with your loop. Are you
sure Cells(x,1) is pointing to the cell you think it is? Cells(x,1), unless
you qualify it, will refer to the active worksheet only so if you have
switched to another sheet you may be looking at the wrong cell. You could
but a breakpoint on that line and test what sheet you are on and the address
of the cell to make sure. Also, while at it, test what the value of
Cells(x,1).Value is and also Len(Cells(x,1).Value) to see if there are any
extra spaces or other characters.
--
- K Dales


"Jack" wrote:

I have tried value it will not work either the the and in the loop should
have been an or but no matter what I try it still will not work.
--
Jack

"K Dales" wrote:

Try using .Value instead of .Text
--
- K Dales


"Jack" wrote:

I need some help with a loop I want to check a range of cells and select only
the cells with a valid product in them for example i want to copy ice cream
but ignore any cells that have nothing in them or have the word product in
them I am trying to use the loop below

If Cells(x, 1).Text < "Product" And _
Cells(x, 1).Text < "" Then
d = x - 1

unfortunately it would appear that the text formatting in each cell hase a
bearing for example product will be selected if the font colour is say blue.
is there anyway around this
--
Jack

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 to check cell contents Steve Excel Discussion (Misc queries) 2 July 29th 09 04:58 PM
check for repetition of cell contents David Excel Worksheet Functions 1 September 14th 06 09:31 AM
Fussy check of cell contents access_mk Excel Discussion (Misc queries) 1 April 19th 06 01:28 PM
IF statement to check cell contents Lance Gray Excel Worksheet Functions 1 May 29th 05 10:53 PM
How to check if cell contents overflow. Alan Savage Excel Programming 1 September 29th 04 02:42 PM


All times are GMT +1. The time now is 03:36 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"