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

  • Home
  • SEARCH
  • 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 8230317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:05:33+00:00 2026-06-07T17:05:33+00:00

I am pretty new to programming in vba. I need some coding help which

  • 0

I am pretty new to programming in vba. I need some coding help which I am not able to find the solution after I tried Googling for the solution.

Currently I have a self-defined type called category mapping. The type will be used to contain the items which I want to put as the option for the vadliation list. It looked as below:

Public Type categoryMapping
    messageKey As Long
    description As String
End Type

An example of the categoryMapping is to store gender codes, 6000 stands for Male, 6001 stands for Female.

Display of the Validation List
As I have all stored them in an array, displaying them is not easy. What I have done is as below:

'Validation drop down list for the whole row
If Has_Elements(mapping) Then
    Dim code As String
    Dim options() As categoryMapping

    code = ""
    options = mapping

    Dim j As Integer
    For j = LBound(options) To UBound(options)
        code = code & options(j).messageKey & ": " & options(j).description & ","
    Next j

    With Range(Rows(7).Address).Validation    'TODO: Need to refactor
        .Add Type:=xlValidateList, _
        AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, _
        Formula1:=code
        .InCellDropdown = True
        .InputMessage = "Please choose from of the following"
        .ShowInput = True
    End With
End If

Is there a easier to display them since I have already put all the item to be displayed into a array? Is it possible that I can call the array directly?

Use Cells
From the code above, it can be seen that I have use the address of the whole row to contain validation list, because actually what I want is the whole row, except the header cells to contain the validation list.

With Cells(7,1).Validation    'TODO: Need to refactor
    .Add Type:=xlValidateList, _
    AlertStyle:=xlValidAlertStop, _
    Operator:=xlBetween, _
    Formula1:=code
    .InCellDropdown = True
    .InputMessage = "Please choose from of the following"
    .ShowInput = True
End With

I tried using the code above to do, but it fails. Is there any way to go about doing it?

Combine multiple validation delete

Due to the problem mentioned above, I need to put in the code to delete the validation list for some column, as shown below:

'Delete the unneccessary validation
'TODO: refactor the code so that write in 1 line
Range(Columns(1).Address).Validation.Delete
Range(Columns(2).Address).Validation.Delete
Range(Columns(3).Address).Validation.Delete
Range(Columns(4).Address).Validation.Delete

Is there some ways that I can combine all the delete validation into a single statement?

Display part of the option

As you can see from above, when my users select a option from the validation list, the whole string appear.

For example, if I have “6000: Male” & “6001: Female” as the option, and I choose Male, I wished for “6000” to appear instead of “6000: Male”. Is there a way to do it?

Validation data not exist after reopen

After I generate the validation list, I close the program and reopen it, there is a error that say “Excel found unreadable content in ‘File name.xls’. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.

When I click Yes, my excel open but all my validation list is gone! And I got the below as a error message.

–
error064240_01.xml
Errors were detected in file ‘file_name’
–
Removed Feature: Data validation from /xl/worksheets/sheet2.xml.part

I was guessing that the error occur because the option in the validation list is not stored in the worksheet, but it is stored in the program memory, hence when I closed the program, the memory is loss.

If my guess is correct, is there any way to go around solving this problem? I was thinking of creating another worksheet that contain all the data in the validation list and let my cell validation list refer to them, but is there better ways to store them in the same worksheet?

  • 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-07T17:05:35+00:00Added an answer on June 7, 2026 at 5:05 pm

    The unreadable content is because you are storing the validation list in an array in memory. As soon as you close the worksheet, that array goes out of scope and ceases to exist. Rather than storing it in an array, write the list to a worksheet somewhere, I normally create a new sheet called lists.

    The actual validation for your cell won’t use VBA. Just create a dynamic named range (using offset() and counta() to populate your validation list from the relevant column in the lists sheet. Then use your VBA code to write the array above to that column. (http://chandoo.org/wp/2010/09/13/dynamic-data-validation-excel/)

    As far as displaying different text in the validation and the dropdown, that sounds like more trouble than it is worth. Is it possible to just resize your cell so it only shows the first 4 digits?

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

Sidebar

Related Questions

I'm pretty new to database programming, and I'm in need some help writing what
I'm pretty new to Python programming and would appreciate some help to a problem
I'm pretty new to RoR programming. I remember reading on some tutorial (forgot which)
I'm pretty new at this programming thing...and I need to make a program which
I'm pretty new to android-programming. Can you help me, what i need to show
I'm pretty new in iphone programming and have stumbled upon this issue which I
I'm pretty new to Android programming, and I've looked around but haven't been able
Pretty new to C# but not new in programming in generally. I'm still trying
I'm pretty new to Android programming so any help would be great :) I'm
I'm pretty new to programming and am having some trouble understanding the output of

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.