+ Reply to Thread
Results 1 to 11 of 11

Select case on range name

  1. #1
    Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    449

    Select case on range name

    Hi

    I think I am being a bit daft probably because I've been staring at vba for too long today...
    But I cant get my select case to work. basicially it just validates the data. When I run it nothing errors, but nothing happens either?

    Please Login or Register  to view this content.
    Last edited by mcinnes01; 01-10-2011 at 11:27 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Select case on range name

    Try amending along these lines
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    449

    Re: Select case on range name

    Ammended as suggested and still no joy

    Please Login or Register  to view this content.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Select case on range name

    An example workbook would help. Are they all Named Ranges referring to single cells, if so you need to loop through the Names not the cells

    Maybe
    Please Login or Register  to view this content.
    Last edited by royUK; 01-07-2011 at 01:22 PM.

  5. #5
    Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    449

    Re: Select case on range name

    Here is a very basic example of what I am trying to do. Essentially if the various criteria for each cell aren't met then the relevent msgbox should display
    Attached Files Attached Files

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Select case on range name

    Slight variation on above
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    449

    Re: Select case on range name

    Hi Roy thats great it worked a treat, I'm just having one problem in that I don't want the code below to run until non of the case match. Is there a way of saying "IF NO CASES MATCH THEN ..."


    Please Login or Register  to view this content.

  8. #8
    Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    449

    Re: Select case on range name

    Ok so I have found 2 problems and more or less solved 1 with the select case.

    The problems are that it will go through every case and display every validation prompt that has a matching case.

    The other problem is that I want it to only run the last validation step when all the others pass (ie don't match a case)

    I had a play at just using a more simple approach of nested ifs, this is working how I want it other than it doesn't go all the way through validation if you pass the validation for RES then it stops and wont go on to validation REQ etc

    This is my code

    Please Login or Register  to view this content.
    Last edited by mcinnes01; 01-10-2011 at 07:37 AM.

  9. #9
    Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    449

    Re: Select case on range name

    Ok here is my problem...

    Basically some cell entry variations have multiple validation reasons.

    For example Cells PSC (salary scale) and PPT (salary point)

    If both PSC and PPT are blank then they pass

    If both PSC and PPT have a value they pass

    If PSC has a value and PPT is blank msgbox (you must select a scale point)

    If PSC is blank and PPT has a value msgbox (you must select a salary scale first)

    This is my code for this particular item in the validation, the problem is, is that it will work if they are both blank and if they both have a value and if PPT has a value and PSC is blank

    BUT*** it doesn't work is PSC has a value and PPT is blank.

    How can I over come this, I have about 4 instances where this happens


    Please Login or Register  to view this content.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Select case on range name

    Use Application.WorksheetFunction to check the number of empty cells.

  11. #11
    Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    449

    Re: Select case on range name

    Hi Roy,

    Thanks for the suggestion, I managed to use the worksheetfunction "AND" to allow the elseif to continue.

    Please Login or Register  to view this content.

+ 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