Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    327
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking Data on part of a cell (Excel 2000)

    On my excel form, I am trying to check if the city, province and postal all exist in the same cell. To get data out of part of the cell, I have:
    Split(Range("C8"), ",")(2)

    But if I check by:
    if Split(Range("C8"), ",")(2) = "" then

    I get a subscript out of range error

    How can I check if part of a value would exist on a cell?

    Thanks

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking Data on part of a cell (Excel 2000)

    The error is caused by the fact that there is no second comma in the cell (and hence not more than two parts separated by a comma).

    Try this:
    Dim sVal as string
    On error resume next
    Err.Clear
    sVal=Split(Range("C8"), ",")(2)
    If Err<>0 then
    Msgbox "Some data is missing!"
    'Other code
    Else
    'There are two comma's
    End If
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking Data on part of a cell (Excel 2000)

    if ubound(Split(Range("C8"), ","))<2 then
    'some date missing
    end if

  4. #4
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    327
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking Data on part of a cell (Excel 2000)

    Thanks. I actaully ended up just changing the form because the comma is not the best delimiter to use. There were to may variables to have a whole address on one line.

Posting Permissions

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