Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Check if value does not exist in range.

Hello

I have a small question for the gurus he

I have a spreadsheet with Data. The data is stored in columns A through P
with column labels in row 1. So my column lables are A1:P1

I know how to use:
Cells.Find(What:="SomeColumnLable").Column
To determine which column any particular bit of information is located at.

My question is:
Is there a way that I can use the Cells.Find to check if a column label does
not exist in the range?

Thanks
JC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Check if value does not exist in range.


'I removed the column at the end
Set c = Cells.Find(What:="SomeColumnLable")
if c is nothing then
'enter your code here
else
column_Number = c.column
end if


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=186470

Excel Live Chat

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Check if value does not exist in range.

You might find a call to this function simpler to use within your own
code...

Function IsColumnLabel(Lbl As String, Addr As String) As Boolean
Dim R As Range
On Error Resume Next
Set R = Range(Addr).Find(What:=Lbl, LookAt:=xlWhole, MatchCase:=False)
IsColumnLabel = Not R Is Nothing
End Function

Just pass the function the label text and the range address as a string. For
example...

MsgBox IsColumnLabel("SomeColumnLabel", "A1:P1")

and it will respond True if the label text exists within the specified range
and False otherwise.

--
Rick (MVP - Excel)


"Juan Correa" wrote in message
...
Hello

I have a small question for the gurus he

I have a spreadsheet with Data. The data is stored in columns A through P
with column labels in row 1. So my column lables are A1:P1

I know how to use:
Cells.Find(What:="SomeColumnLable").Column
To determine which column any particular bit of information is located at.

My question is:
Is there a way that I can use the Cells.Find to check if a column label
does
not exist in the range?

Thanks
JC


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Check if value does not exist in range.

Thank you all for your responses.

Joel's approach is the one that works best for my particular project where I
need to check for the non-existance of a particular label and execute code
based on that. So Joel gets the check-mark this time.

Thanks again
JC

"Rick Rothstein" wrote:

You might find a call to this function simpler to use within your own
code...

Function IsColumnLabel(Lbl As String, Addr As String) As Boolean
Dim R As Range
On Error Resume Next
Set R = Range(Addr).Find(What:=Lbl, LookAt:=xlWhole, MatchCase:=False)
IsColumnLabel = Not R Is Nothing
End Function

Just pass the function the label text and the range address as a string. For
example...

MsgBox IsColumnLabel("SomeColumnLabel", "A1:P1")

and it will respond True if the label text exists within the specified range
and False otherwise.

--
Rick (MVP - Excel)


"Juan Correa" wrote in message
...
Hello

I have a small question for the gurus he

I have a spreadsheet with Data. The data is stored in columns A through P
with column labels in row 1. So my column lables are A1:P1

I know how to use:
Cells.Find(What:="SomeColumnLable").Column
To determine which column any particular bit of information is located at.

My question is:
Is there a way that I can use the Cells.Find to check if a column label
does
not exist in the range?

Thanks
JC


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Check if value does not exist in range.

You might want to consider substituting your exact range (A1:P1) in place of
joel's more general Cells reference just in case your last use of Find
searched by columns instead of by rows; otherwise the Find function will
search every cell in each column until it either finds the label text or
runs out of columns to search. Alternately, you can specify the xlByRows
parameter of the XlSearchOrder argument in joel's function call to make sure
it searches Row 1 first, although if the label is not there, joel's function
call will still do more work than if you specify the range directly as the
search would go through every cell on Row 1 until it runs out of columns.

--
Rick (MVP - Excel)


"Juan Correa" wrote in message
...
Thank you all for your responses.

Joel's approach is the one that works best for my particular project where
I
need to check for the non-existance of a particular label and execute code
based on that. So Joel gets the check-mark this time.

Thanks again
JC

"Rick Rothstein" wrote:

You might find a call to this function simpler to use within your own
code...

Function IsColumnLabel(Lbl As String, Addr As String) As Boolean
Dim R As Range
On Error Resume Next
Set R = Range(Addr).Find(What:=Lbl, LookAt:=xlWhole, MatchCase:=False)
IsColumnLabel = Not R Is Nothing
End Function

Just pass the function the label text and the range address as a string.
For
example...

MsgBox IsColumnLabel("SomeColumnLabel", "A1:P1")

and it will respond True if the label text exists within the specified
range
and False otherwise.

--
Rick (MVP - Excel)


"Juan Correa" wrote in message
...
Hello

I have a small question for the gurus he

I have a spreadsheet with Data. The data is stored in columns A
through P
with column labels in row 1. So my column lables are A1:P1

I know how to use:
Cells.Find(What:="SomeColumnLable").Column
To determine which column any particular bit of information is located
at.

My question is:
Is there a way that I can use the Cells.Find to check if a column label
does
not exist in the range?

Thanks
JC


.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 342
Default Check if value does not exist in range.

Try:

Cells.Find(What:="").Column

Tom
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
Check for a tab if it is exist Farhad Excel Discussion (Misc queries) 2 December 21st 08 07:31 PM
Check if shape exist Hans Hubers Excel Programming 3 May 26th 08 02:45 PM
Check if pivot already exist Paul Wright Excel Programming 0 September 11th 03 05:45 AM
Check if pivot already exist Tom Ogilvy Excel Programming 0 September 11th 03 05:43 AM
check if a worksheet exist - VBA Warren Excel Programming 1 September 10th 03 05:02 AM


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