+ Reply to Thread
Results 1 to 3 of 3

check a row of data for a value return a boolean result

Hybrid View

  1. #1
    Registered User
    Join Date
    09-26-2007
    Posts
    26

    check a row of data for a value return a boolean result

    I need help to determine if a value exists in a column header and then based on that determination give it a boolean value (TRUE = it exists, FALSE = it doesn't exist) and then, if it does exist, store that column location into an integer variable.

    My problems occur when the column name doesn't exist. Since there is no value, it can't determine if the value is > 0 so it hangs.

    Any help would be appreciated.

    -js999


    
    'Variable to store column number if column exists
    Dim JoinMktClassCol_Number as Integer        
    
    'Variable to recognize whether column named 'JoinMktClass' exists
    Dim JoinMktClassCol_Exists as Boolean
    
    
    ActiveWorkbook.Sheets("Proposed").Activate
        JoinMktClassCol_Number = Cells.Find(What:="JoinMktClass", After:=[A1], _
            Searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
        MsgBox "JoinMktClass is in column: " & JoinMktClassCol_Number
        
    If JoinMktClassCol_Number > 0 Then
            JoinMktClassCol_Exists = True
    Else: JoinMktClassCol_Exists = False
    End If

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Js999,

    The Find method returns a Range. If the Find is unsuccessful then it returns a special value called Nothing.
    ' Variable to store column number if column exists
      Dim JoinMktClassCol_Number As Range        
    
    ' Variable to recognize whether column named 'JoinMktClass' exists
      Dim JoinMktClassCol_Exists as Boolean
    
    
    ActiveWorkbook.Sheets("Proposed").Activate
        Set JoinMktClassCol_Number = Cells.Find(What:="JoinMktClass", After:=[A1], _
            Searchorder:=xlByColumns, searchdirection:=xlPrevious)
    
      If Not JoinMktClassCol_Number Is Nothing Then
         JoinMktClassCol_Exists = True
         MsgBox "JoinMktClass is in column: " & JoinMktClassCol_Number.Column
      Else 
         JoinMktClassCol_Exists = False
      End If
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    09-26-2007
    Posts
    26
    Leith,

    Thank you! It works perfect. Hopefully, someday I will get to the level where I can return the favor. Emphasis on 'someday'.

    -js999

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1