How can using user defined function in custom data validation? - vba

In my Worksheet I have a Table and want to define Data validation for a column that contained the date, as bellow:
=S2M(B2)<>"Error"
In above, S2M() is a user defined function for converting date from Persian date to Gregorian date, because checking input date is right.
But excel is not letting me use user defined functions in Custom Data validation.
This error shows: A named range you specified cannot be found.
Please note that I was using bellow code in Custom Data validation and that works, right.
=AND(LEN(B2)=10;ISNUMBER(IFERROR(VALUE(MATCH(VALUE(MID(B2;1;4));INDIRECT("intTable[Year]");0)&MATCH(MID(B2;6;2);INDIRECT("intTable[Mounth]");0)&MATCH(MID(B2;9;2);INDIRECT("intTable[Day]");0));FALSE)))
Explain is a Persian date example: 1396/05/25
Thanks.

You can do that. Select B2, or whichever cell in row 2 you want the validation to apply to. Now define a name called, say, IsValid, using:
=S2M(B2)<>"Error"
Now in the data validation box, all you need to enter is:
=IsValid
in the source box and make sure to uncheck the Ignore Blank option.

Related

When setting a date with v-date-picker v-text-field is not populated with selected date when v-mask is used

Has anyone seen/solved this issue? I have a component that utilizes v-date-picker and v-text-field. The text field is using v-mask for dynamic masking. The masking works well when date is typed in. However, when the date picker is used, it causes the text field's contents to be updated multiple times and the functions used to construct the mask are called multiple times as well. As a result, the text field ends up blank, and I get an error stating that time value is invalid.
I understand that the date picker is performing its own checks, and the format it's using for dates is different from what I need. I tried a workaround to limit the number of calls coming from the date picker and populate the text field with a saved value at the last call. But I either still get a blank field or the 'invalid time value' error.
When I set breakpoints in the masking functions, I do see the date in the text field before it disappears.

Excel - 2 data validation in the same cell

I want to combine 2 data validation into one cell. I can do it with separate cell, but had no idea on how to combining them.
First Validation: a list contains certain options for user to choose, and an others if it is not inside the list.
When Others is being selected, User can input their own data.
First Validation Setting
Second Validation: a cell that needs to starts with a certain format, else error message will appear. e.g. users can are only to allow to input in this format ABC xxxxx
Second Validation Setting
I want to combined the list validation and the custom validation to one cell F2. So users can choose either the options given, or choose other and input the data they want, but the format must be ABC xxxx.
Any suggestions and helps are appreciated. Thanks in advance
Thanks #pnuts & # YowE3K, with the reference from here. I had successfully achieve what I want.
Solution: Right Click F2 -> Format cells -> Custom -> Type "ABC "#

Changing the title of a column in a PivotTable

I am having trouble changing the title of some columns in a pivot table. I'm trying to make them have dates in them. Each date 6 days further from the last.
Like this
But, I cannot get an equation inside the column title to stay, every time I type in the equation and press enter, it evaluates to either 0 (If the format of the cell is number or general), or 1/0/1990 (If formatted as a date). I checked the value of the cell by =ISTEXT(A1) and it evaluates as true. No matter how I format the cell. So I can never change the title to look like the picture. Any ides?
Here is what I have.
TRUE is the result from ISTEXT()
Even if I manually enter in the formula via the function arguments, it'll show up correct, but when I click ok. It will go back to either 0 or 1/0/1990
Here's the original page
https://drive.google.com/file/d/0B3p8Jm7oNAo4ZUN0Qk1mR1cxYmM/view?usp=sharing
In Excel, dynamic values (formulas) in the header of a table-formatted table are not allowed.
Instead, you can first generate your table header and then format the table as (pivot-)table. You should get a message saying that the header row will be converted in static text (with correct format).

Inconsistent recognition of ranges (No errors thrown)

This is code from Excel 2010. All of the code resides within the workbook itself. Information is gathered using internal forms and the code is run.
I have code that retrieves data from a spreadsheet and populates an object with that data. The row number is dynamic as it is dependent on the form input. The column is by the header, not the column number. The following code works perfectly but for two anomalies:
cTank.RowForTankSpecs = rNum
cTank.MP = .Cells(rNum, Range("MP").Column).Value
cTank.Form = .Cells(rNum, Range("formName").Column).Value
cTank.TankProcess = .Cells(rNum, Range("Process").Column).Value
cTank.Location = .Cells(rNum, Range("Location").Column).Value
cTank.TankName = .Cells(rNum, Range("Tanks").Column).Value
cTank.tankID = .Cells(rNum, Range("TankID").Column).Value
First:
The cTank.TankName is retrieving information from a column named "Tanks". That column does not exist. The actual column header is "Tank". But, it is retrieving the correct information. If I change the name to what it really is (Tank), it does not work.
Second:
When the cTank.TankID line is executed, I get the following error on the Range("TankID"):
Runtime Error 1004: Method 'Range' of object '_Global' failed
This one has the appropriate header (column header), but it is not recognizing the range.
I have tried simple things such as changing the order of the code, but it doesn't help. As earlier stated, the other lines work. Later in the program, information is gathered in the same manner but using another worksheet from the same workbook, and none of them are working. I've double checked that strings are strings and integers are integers, etc. I've double checked the column headers match the range names. Nothing seems to jump out at me.
I would appreciate any input you may have on the situation.
Thanks in advance.
Steve
Ok. Being pretty sure my code was correct, I went to the spreadsheet itself. For some reason it was recognizing only certain columns and it was recognizing one of them incorrectly. So I started highlighting the columns that worked and also the columns that didn't. What I noticed was that on the columns that were being recognized, that column header was displayed where the cell location is normally displayed whereas on the columns that were not being recognized, the cell location (i.e. A1, A2, etc.) for the header was being displayed and not the header title itself. The incorrect label was showing up for one of them. As it turns out, the mislabeled column was one that I had used for a form dropdown menu. So, I checked the name manager, and the ones that were working were listed. So anyway, using the name manager, I added named ranges using the headers. Now, when I select the columns, the column header(named range) appears in that window and now, the code works.
Thanks guys for your input. I really appreciate it.
Two things you can do:
Do not use use Range, but as it seems you are using names, use Names("Yourname").Referstorange.
OR
Make sure your names are set up correctly using the Name Manager in Data Ribbon.

Storing user inputs for retrieving later

I have a spreadsheet where the user inputs various details on an inputs page and then presses a calculate button to get what they want. The inputs are strings, numbers and dates.
I want to save the inputs for each calculation for the user so that at a later date they could enter the calc id and not have to renter the inputs.
One simple way I thought of doing this was to copy the inputs when the calculation is run to another sheet with the inputs in a column with the calc id. Then just save future inputs in a separate column and lookup the correct column to retrieve the inputs at a later date.
I read this question - What are the benefits of using Classes in VBA? and thought it would be good to make a class called CalculationInputs that had all the details stored in one object. This may be overkill for what I need but i wanted to ask how other people would solve this simple task.
You can use Names to define variables within the scope of a workbook or worksheet. Typically these are used to define ranges, and more specifically dynamic ranges, but they can also be used to store static/constant values.
To create a Name manually, from the Formula ribbon, Names Manager:
Click on the "New" button, and then give it a meaningful name:
Make sure you put ="" in the "Refers To" field, if you leave it blank, the name will not be created.
Then when you press OK, or any time you go to the Names manager, you will see a list of all available Names in the workbook.
You can edit these through the Names manager, which is probably tedious, or you can easily use VBA and inputs to control them, for example:
Sub Test()
ActiveWorkbook.Names("MyAddress").RefersTo = "734 Evergreen Terrace"
End Sub
You could do something like this to capture the value, our use other macros or user firm code to assign the value to the Name.
Activeworkbook.Names("MyAddress").RefersTo = _
Application.Inputbox("please enter your address")
Etc.
If you run this, and then review the Names manager, you'll see the value has been updated:
In VBE, you can refer to the name like:
Debug.Print ActiveWorkbook.Names("MyAddress").Value '# Prints in the immediate pane
Range("A1") = ActiveWorkbook.Names("MyAddress").Value
These can also be accessed (read) from the worksheet, like: