How to find data range dynamically in Excel - excel

I'm trying to implement data validation in Excel using VBA. I'm able to implement data validation before save excel event but I'm having trouble in finding range, where user gave the input in excel.
For example, I want to implement data validation from A1:C50 but if user enters data from A1:C45, remaining cells will fail due to validations. SO I want to find range A1:C45 and do validations.
Can you please let me know how can I find user data range in Excel?

If I am understanding your question correctly you only want test the data if the row above it has been filled in. If so, you can do this without VBA. In your data validation select 'Custom' and enter the formula below (example for cell A46):
=AND(A46>0, A46<=10, COUNTBLANK(A45)=0)
This will check for a value between one and ten but only if there is an entry in the row above.
If this doesn't help please provide more information around your question.

Related

How to submit cell data into other cells in excel

Think I might be reaching a bit here, but I’m trying to find a way of sending / submitting cell values in excel to other cells. Here’s the example;
In a cell I have a car name
I’ve set my workbook up to use this cell as a field to enter data and the system calculates where what I enter into a separate table, and returns a confirmation that the car I want to look for exists. I might then delete the data in the field to repeat the search. Here’s what I’m trying to solve…
If the car doesn’t exist, I want to somehow send or copy the data from the field (by clicking something or a formula) and send it into another table automatically to list as “cars that were searched for but didn’t exist” type area, how could I do this?
Many thanks

How to search a website using a range of cells in excel to extract specific data

I'm trying to search the website "capfriendly.com/players/" using a column of cells and import the "Cap Hit" value back into excel in the adjacent column for each.
I'm a complete beginner when it comes to programming, so I've mostly been trying to learn from previous questions such as this one: excel macro to search a website and extract results
I'm still pretty perplexed, especially with how to extract just the specific value I'm looking for. Any guidance would be greatly appreciated.
I don't know which version of Excel you work with.
Anyway you can try this :
Create a new sheet.
Go to Data in the ribbon to get external data and choose "From web".
Input the url of your page ie https://www.capfriendly.com/browse
After a moment you should retrieve "Results" data that you can load with or without structure modifications. You now have a data table in your new sheet.
You can now access it with Vlookup or similar function, with VBA code or with formulas, to put specific data on specific cells of specific sheets like you need to.
Hope it helps.

How to predefine the required format of a cell?

I currently build a dashboard in Excel to track forex trades. One worksheet is for adding new trades to the database. Within this worksheet i have several fields that the user needs to fill in order to add the trade to the database. Now I want to avoid that the user inserts wrong data (regarding format) in the cells and therefor crashes the outputs from the database later on.
How can I define such criteria via VBA? For example the field date to have the format YYYY-MM-DD and the field Trading Volume XX,YY so the user can't (accidentally) insert X,YY etc. For dropdown fields it is easy by defining the inputs within the dropdown menue itself, but i need some solution for the manually filled cells.
I will then define a msgbox to pop up and inform the user to meet the required input formats.
Thank you very much in advance!
Some key words would help me, I can then get into deeper it and code it by myself.
Rather than using code could you not use data validation and force entry of a date, numeric value etc.?
If you define the cell format to be custom 'yyyy-mm-dd' then apply data validation with a defined date range Excel will auto format it for you even if they enter dd/mm/yyyy and alert if an invalid entry is added.
Then for a belt and braces approach run a routine at Save that will mimic what your database will do and alert if there is still invalid data see https://learn.microsoft.com/en-us/office/vba/api/excel.workbook.beforesave
I would also lock down the sheet to avoid users adding rows / columns or moving your cells around.
enter image description here

How can I restrict data entry for an array of cells if the prior cell has not been populated?

I am creating a user form for work where the user can select up to 15 clients from a list using excel data validation. However, I only want the second cell to be available to populate once the first has been populated, and the third when the second is populated etc. I also want the color of the cell to change when it becomes available to populate
I've tried using regular excel data validation and conditional formatting, but it seems limited in that I would have to create a separate data validation for each cell, rather than making one data validation command for the entire range
I would think using an if(IsEmpty) would solve my problem but as a fairly new VBA user I am having trouble determining the most efficient way to incorporate the list data validation into the general entry restriction.

Is it possible to base data validation on a string in a single cell in excel 2010

I am building a multilevel dependent dropdown structure in Excel based on a parent-child structure. Building this with vba is not a problem but the problem is reopening the file. It removes the validation because they have too many characters (more than 255?)
The generated validation strings are too long for Excel to store so they are removed after reopening.
A solution could be to write the validation string in a cell and base the validation on this cell value. Only problem is when i link the data validation to this cell its only one option.
the value in the cell is something like A,B,C,D (already tried with or without "")
Does anyone have a suggestion for an excel formula to use in the data validation to generate multiple options from a string like A,B,C,D located in one single cell.
TNX for the support.
The solution was a bit more difficult.
I was able to make it work but only by combining VBA and Excel Formulas. Also i added a value to the dataSource with both the id and optionid in it.
Excel:
For The data validation i use an fuction who utilizes an offset which is dynamic and based on 2 values. This way i dont get the error that a validation is more than 255 characters.
data validation formula:
=OFFSET(List!$A$2;MATCH(CONCATENATE(V18;"|";E18);List!$F:$F;0)-2;1;COUNTIF(List!$F:$F;CONCATENATE(V18;"|";E18)))
One is for the id and one is the optionid.
VBA:
I now use the on change event to produce the values needed for the dropdowns(data validation) but not letting vba insert the values for the data validation. It gets these values via a pre-loaded array which is started with a workbook_open event. (if this isnt loaded it will load it again).
When i select an item it writes the id and optionid to a different cell. I then use these to produce the next dropdowns etc with the offset function. (one dropdown can result in multiple rows of new dropdowns)
Also added some functionality for delete and change (in the middle) events.
Also the onChange event now triggers the next dropdown and write its value if there is only one option. This will of course trigger the next.

Resources