Freeze column content from drop down in Excel - vba

Hi I am new to excel for this kinds requirements.
I want to freeze the cell content (from a drop down) once a selection is made. Users should not be able to modify the entered content. Once the selection is made from data validation list then user can not change it.
Ex. If we have "M" and "F" in drop down(Data validation). Once user select "M" then he will not allow to change this with other option.
Let me know if you need more clarification. Direct me to the answer if question is already there.

I would suggest having conditionals control your validation. For instance:
If your validated list containing 'M' & 'F' is in cell A1, place a condition in say cell A2:
=IF(OR(A1="M",A1="F"),A1,"M")
And then for A3:
=IF(A2=A1,A2,"F")
Then set your validation list to cells A2:A3. By doing this, the dropdown can start unpopulated, a user makes a selection, and then the cells guiding the validation change to the users selection. This is a decent option if you are not comfortable with VBA. Good luck!

Related

Refering to Table cell in Macro

So, I am relatively new to VBA and Programming as a whole,
I know in Excel Formulae, Rather than refer directly to a Cell ($B$27) you can refer to the Column name instead, (#[Condition]).
Now I am aware that this only works on "linear" tables, the formulae will only work on and affect the row its in, but for the table i am working on this is fine.
My question is, is there a way to refer to this inside VBA?
I am trying to create a function that takes the value of a "Condition" Cell and if this is "Other" it will open a custom User form with 3 buttons that allow the user to select the reason why the Condition is "other"
Depending on the button click, the Value of another Cell in the same table (Works Completed) will be changed to what ever the reason they click.
(E.G, user clicks "To be Repaired", the value of "Works Complete" will be changed to "For Repairs"
This currently only works when referred to a Cell directly ($B$27)
Whenever you have a question, concerning the translation of a manual action in Excel to VBA the best answer is:
Start the macro recorder, do the manual action and check yourself.
This is a sample of a recorded macro, selecting Table1, Column3:
Sub Macro1()
Range("Table1[[#Headers],[Column3]]").Select
ActiveCell.FormulaR1C1 = "Testing"
Range("C2").Select
End Sub

How to make a Cell Read Only in Excel without Password using VBA?

I'm trying to set a few specific cells read-only.
How do I lock a specific "selection" (say cell) in Excel? I don't want to use password. I want to make them Read Only.
Another way you can do this is through Data Validation. After you have a cell populated with the desired contents, Choose Data Validation and use the Custom option. For the formula enter =""

Copy data from one part of a userform to another automatically

I am trying to work with an Excel form using VBA that I have customized (I found the original on the web).
I have two tabs: one is called Planning-Deleted, the other is called Planning-Deleted Data. All the data that I enter in the first tab is copied to the second tab when I press a command button called Add to Database.
Is it possible to skip the command button altogether and record the data entered in cell D5 and D6 directly in the second tab and clear these cells for the next records? I have no knowledge of programming and I would appreciate as much clarity and specificity as possible.
If more details are needed, please let me know.
You'll need some trigger to cause the copy operation to happen, for example:
Using the 'Change' event, you can trigger some action any time some value is entered into a sheet:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet2.Range(Target.Address).Value = Target.Value
End Sub
This code will copy any data entered into the first sheet into the same cell on the second sheet. 'Target' in this case is the cell where data was entered.
I'm not sure if this what you want though, since you also want to clear the cells after the copy. Can you describe when the copy-and-erase should occur, if not from clicking a button?
Also, your question doesn't seem to match your question's title. Can you clarify a bit what you are trying to accomplish?

Cell reference in an Excel Macro

I have a macro to write, quite simple.
It just pulls numeric values from a Database and pops them into certain cells.
Problem is, I want the layout and design of the worksheet to be able to be changed without a care of the underlying macro. So obviously the cell references will change, for the cells that I need to populate with data.
Is there a way to mark a cell - say with "VALUE1" - in the background, and then reference that cell by using "VALUE1" - without needing to know its exact Cell position? So that its value can be updated - wherever it is on the Work Sheet?
Is there a TAG property or something that could be used? Although a function would have to be written to search through all the TAGs of every cell, but that is OK.
Any ideas?
I think this could be a bonus for any Macro developer :)
Office Documentation: Define and use names in formulas.

Show Cell Range on UserForm; then update

I've been using a crude method to help the user update some cells - by having them in a sheet. Is there any way I can display the various ranges in a userform, one by one, then have the user update them, click a button and move onto the next one?
Essentially, can I have Excel automatically generate an input form based on a range? The process of updating and saving back to the sheet I can do; it's the production of the correct form that I can't.
It's possible to do this, but the only way I can think of is to make a userform that automatically populates itself based on a range passed in. This way you could have different macros in Excel that call the form to populate based on different ranges. I built a proof of concept Excel file for trying this, and it seems to work, the only issue I can think of being that you need to figure out a way to tell the user what input field is what.
I think what needs to be done is to add controls programmatically to a userform (I name the textboxes as the cell address it's going to populate) then when the form is closed loop through all the textboxes and populate the cells with the textbox values.
You can see what I did at:
https://my.syncplicity.com/share/uicgbs3rl0/InputForm.xls
I think all that would need to be done is for you to work out how to add labels for the textboxes, and make sure the form is resized based on the controls you add...
I am not quite shure what you are looking for, but you could insert a second sheet and use it as a "form". An other way could be a dialog box with an input field.
Either way, you present the cells you want the user to change one by one, using a vba-function. You implement a "previous field" and a "next field" button, so the user can step through the range of cells. If the user hits "next field", you save his input and take the next cell from a previous defined range of cells.
You could have a "config field" in which you define the range of cells you want to change.
This is pretty rough and old-fashioned but if you have the data in standard list format - i.e. column headers in the first row of your range and then one record of data in each row below - then selecting a cell within the range and going Data > Form will give you a crude input form with roughly the functionality you need.
You can also do this in VBA by calling the ShowDataForm method of the appropriate worksheet. Just select a cell within whichever range you need first. The macro will remain paused until the user closes the data form