I inherited a workbook from someone who is long gone. They put a button on the dashboard that activates the following code.
Private Sub CommandButton2_Click()
Sheet5.ShowDataForm
End Sub
It brings up a form with all the elements/columns on that sheet, with all the buttons need to put in more data. I like the simplicity, but is there any way I can add in validation? Things like:
In the 7 fields it collects, 5 are required.
In the first field, I want to make sure a number is entered and that number isn't on the list already.
I can code these, I just don't seem to have an entry point into the DataForm.
Thanks!
Chuck
While that won't be the answer you like to hear, but according to THIS, your request can't be done in a simple way. So either create your own userform or dive extremely deep in the win api. Sorry :(
Related
I am relatively new to all this so please be kind.
I have some DTPickers, these DTPickers are supposed to fetch data from cells and contain that data when the userform is opened. In this case I have the below code to do that when a button to navigate to the mutliform page is clicked.
DTPicker1.Value = Sheets("FirstName").Range("B2").Value
DTPicker1.CustomFormat = "dd/MM/yyyy"
Furthermore I would like the date to be changed and for the value to be updated within the userform, so I got myself some code to do that as follows:
Sheets("FirstName").Range("B2").Value = DTPicker1.Value
This is run during the DTPicker change event. This is all well and good except there needs to be 20 of these DTPickers. And that means an awful lot of coding the exact same thing again and again and again.
Is there any way to create a loop where I can specify a range for all the information to populate into the 1-20 DTPickers as the multiform page is opened and then when any of their information is changed for that to be stored back into those cells, without having to put the code above into every single DTPicker change event.
IF there is anything at all please help me out, and please if you could also specify where to put any code as well because I'm really not great at this. Thank you.
I reviewed the answer to the question at the link below. This seems to match my need, but I am not able to get it to work for me. What am I doing wrong so this will work. This code can be a great tool for me to limit the free distribution of my spreadsheet which I have commercialized.
Thank you for the help.
How to prevent free distribution of a commercial Excel spreadsheet
When I put the code into the modules and save the file, when the file is opened I am receiving the following error.
Compile Error:
Sub or Function not defined
It then highlights the reference to "Refresh_Serials".
I am running this currently on Excel 2007. Do I need to try it on a newer version of Excel maybe?
I have used the same code as included in the link below.
I would expect it to do as expected per the original post, although I am not 100% sure exactly what the outcome should be. Maybe part of my gap at this point is that I haven't yet established the HTML table. Could I use a "Google Sheet" instead with a table in it?
If you want this Workbook to be compatible for Specific Users only. Then one way to achieve it is to add a WorkBook_Open event. Like:
Private Sub Workbook_Open()
If Not Application.UserName = "Mohit Bansal" Then
MsgBox "Not the Correct User"
ThisWorkbook.Close False
End If
End Sub
Change the Name as Per the User, and lock the VBA Project. You can even make a list of names to check from if multiple users are going to use it.
This will make sure that only one user is able to use the Workbook.
There are obviously other complicated & efficient ways to achieve this, but I prefer this one for Simplicity.
Looking at the linked to code source (what the actions are that follow that line) and the coding style of the author I think that Refresh_Serials is in fact a label. It should be Refresh_Serials:. The lack of the ":" means the compiler is expecting a sub/function of that name. As there are no GoTo statements these labels, there is another proper label further on,SerialVerified:, are unnecessary and confusing. They could simply be comments. Better still, go more Single Responsibility Principle and have functions/subs with names akin to those labels and shift the relevant re-factored code into them.
I have a Form in an Excel VBA project that has many textboxes with names I'd need to change. For instance, names in the projects are: Fees01TBX; Fees02TBX; Fees03TBX, and so on. There are 40 textboxes like these, and I need to change the names into a sequence I can manage better. For instance, I'd need to have them with these names: Expenses01; Expenses02, Expenses03, and so on.
I tried to change it using some code like (just for one textbox):
Sub ChgName()
MyForm.Fees01TBX.Name = "Expenses01"
'Doing this for each one would not be a problem, I can array the sequence.
End Sub
I think it should possible to change the name of a textbox in a form by code, but how?
Make sure you ticked Trust Access to the VBA Project Object Model in security settings:
Sub Rename()
With ThisWorkbook.VBProject.VBComponents("MyForm")
.Designer.Controls("Fees01TBX").Name = "Expenses01"
End With
End Sub
But if Fees01TBX had code you have to change this as well, but for 40 TextBoxes you could do it manually
I inherited a file from a co-worker that is no longer with the company.
In the file are about two dozen of Sub's, with a lot of duplications and redundancy's. There are about a dozen of userform inputboxes in the excel file.
Is there an easy way to check if a certain sub is linked to an inputbox?
I know I can check for each inputbox which Sub is linked to it, but I want to check for it the other way around.
Set breakpoint at every sub. Having set that, play with inputbox in any way you can imagine. If this triggers any sub, you will see that, because code will stop at the breakpoint.
This is most straightforward approach I can think of.
I have the following VBA code, which should show a dataform from another hidden sheet.
Sub CoverageBssEntry()
Application.ScreenUpdating = False
Sheets("myhiddensheet").Select
Range("myTable[#All]").Select
ActiveSheet.ShowDataForm
End Sub
When I run this, the data form does not containt the labels and inputboxes of this table.
Any help is really appreciated, because it is driving me nuts! My only other option is to spend time to build custom made user forms, while this would do perfectly.
You cannot select a hidden sheet. And anyway the .Select statements are not necessary
Try
Sheets("myhiddensheet").ShowDataForm
The fix is to use:
ActiveSheet.Cells(x,y).Select
prior calling the .ShowDataForm, works like a jiffy!
I think there are genuine constraints with the ShowDataForm command. It works fine if invoked outside of VBA while in a specific range. But once coded into VBA, it will only return the form for the first table in the referenced worksheet, even if a macro was recorded to perform that action.
I cannot tell why. Maybe because the showdataform event is tied to the worksheet and not to the table or list selected when it is called. Sorry guys. Maybe microsoft will improve this in the future.