Data Validation

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,913
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a workbook where I have added some code so that a cell can only take certain values, via Data Validation.

The list exceeds 255 characters, ie the list of available values are:

Code:
"a,b,c,d,e, etc. "

When I save, close then reopen the workbook, I get this error message:

[code]

We found a problem with some content in 'Your workbook.xlsm.' Do you want to try to recover as much as we can? If you trust the source of this workbook, click Yes.

then it shows:

Code:
Removed feature: Data Validation from /xl/worksheets/sheet1.xml part

Has this got anything to do with the Data Validation being too long?

Thanks
 
Last edited:
Create any worksheet event that gives you a Range parameter and you will see. For example:

Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

According to you, you're passing an object ByVal, so you can change it without affecting the "original" object?

No, that is not what I said.

When you pass an object, you actually pass a pointer to the object's address in memory. If you pass that pointer ByRef, then the called routine can make that pointer point to something else. If you pass it ByVal, it can't. Passing ByRef or ByVal does not at all affect what you can do with the object in question, only what you can do with the pointer.

That is why worksheet events pass the Range ByVal - there could be multiple routines monitoring that event and they can all effect changes to the range in question, but none of them can alter which range is being referred to. If you passed the range ByRef, the first listener might unintentionally change the range from say A1 to A2, and subsequent events would be given the wrong range.

Here's a simple example to show the difference:

Rich (BB code):
Sub foo()
    Dim rg As Range
    Set rg = Range("A1")
    Debug.Print "rg starts assigned " & rg.Address
    Call rangeByVal(rg)
    Debug.Print "rg is now " & rg.Address
    Call rangeByRef(rg)
    Debug.Print "Rg is now " & rg.Address
End Sub
Sub rangeByVal(ByVal rgin As Range)
    Set rgin = Range("A3")
End Sub
Sub rangeByRef(ByRef rgin As Range)
    Set rgin = Range("A3")
End Sub
 
Last edited:
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
No, that is not what I said.

When you pass an object, you actually pass a pointer to the object's address in memory. If you pass that pointer ByRef, then the called routine can make that pointer point to something else. If you pass it ByVal, it can't. Passing ByRef or ByVal does not at all affect what you can do with the object in question, only what you can do with the pointer.

That is why worksheet events pass the Range ByVal - there could be multiple routines monitoring that event and they can all effect changes to the range in question, but none of them can alter which range is being referred to. If you passed the range ByRef, the first listener might unintentionally change the range from say A1 to A2, and subsequent events would be given the wrong range.

Here's a simple example to show the difference...

Apologies I misunderstood what you said. You are absolutely correct and thanks for the clarification given.

I also didn't quite explain myself very well in my own posts but immaterial. Your point is well made.

Regards.
 
Upvote 0

Forum statistics

Threads
1,222,907
Messages
6,168,963
Members
452,228
Latest member
just4jeffrey

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top