Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:05:58+00:00 2026-06-03T14:05:58+00:00

Normally it is possible to apply data validation in excel through vba but i

  • 0

Normally it is possible to apply data validation in excel through vba but i am having a specific problem

I am using the indirect method for applying validation,normally when i dont use vba i get a warning by excel that “source currently evaluates to an error,do u want to continue?” (this is because cells which indirect refers to may be empty), now i can easily skip this error in excel by clicking “Yes”

Here’s the link http://www.contextures.com/xldataval02.html (Dependent validation lists)

But when i try to perform the same thing using vba i am getting a runtime error,there is no friendly prompt which allows me to continue.How can i handle this kind of error.

On error resume isnt working because then vba doesnt apply validation at all.

Here’s the code

Set rng = ThisWorkbook.Sheets("input").Range("AB11:AB65536")
With rng.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:= _
    "=INDIRECT(cablecode&""_depth_""&$Q11&""_""&$Z11&""_values"")"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

cablecode is a static named range

Q11 and Z11 refer to inputs in that particular row

depth and values are normal strings

cablecode can have two values = “is” or “iec”

Q11 can be “xlpe” or “pvc”

Z11 can be “al” or “cu”

since cablecode is constant for whole project ive referred to it directly,
Q11 and Z11 can be different for different rows so ive referred to them seperately

The whole string comes out to be
“is_depth_al_xlpe_values”
similarly different permuations,and all named ranges are already defined

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:06:00+00:00Added an answer on June 3, 2026 at 2:06 pm

    I suppose the following line needs correction from

    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:= _
        "=INDIRECT(cablecode&""_depth_""&$Q11&""_""&$Z11&""_values"")"
    

    to

    dim cellToBeReferred as string
    cellToBeReferred = cablecode & "_depth_" & Range("$Q11").Value & "_" _
    & Range("$Q11").Value & "_values"
    
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:= _
        "=INDIRECT(" & cellToBeReferred  & ")"
    

    Taking the string out will help you debug the issue and figure what is the value of named range, you’d want to refer to. See what value cellToBeReferred results into and correct the concatenation using above.

    EDIT after reading OPs comment

    In that case, surround the INDIRECT with ISERROR and give a dummy cell reference.
    For e.g.

    "=IFERROR(INDIRECT(" & cellToBeReferred  & "), Z1)"
    

    Where Z1 is a cell to be referred if INDIRECT fails.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to hide VBA code, normally accessible from Excel's VBA Editor (
Normally boot strap loaders are written using assembly languages. Is it possible to dot
Normally validation of simple email is: /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ This will validate email like test@test.com But
Is it possible to explicitly use a CollectionViewSource inside a data template? Normally we'd
Normally colors are called through their hexadecimal associations, but in the code is it
Normally, when tabbing through controls on a form, when the focus is set to
Normally, when using the XMLSerializer to automagically serialize an ISerializable object, a .dll file
This might not be possible but before I rewrite part of my application I
Normally HTML check boxes are grouped based on name. Is it possible to group
Is it possible to have a contiguous link, where the text is normally underlined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.