VBA Excel dataform not displaying the right input and fields - excel

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.

Related

How to find out if a sub is assigned to any userform inputbox

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.

Macro for calculating specific cells

I am trying to make a button so I can recalculate a certain area inside of my worksheet. However after having looked at several tutorials I cannot figure out what I am doing wrong.
Here is my code:
Sub ReloadPlanet()
Worksheets("Sheet1").Range("E9:H27").Calculate
End Sub
Any feedback as to what I am doing wrong?
edit
Here is a bit more detail on the sheet itself:
Each of the commands I want refresh are VLOOKUP commands

Sheet / Range Select (combined) not working

Something has changed in my VBA that is not allowing me to complete certain routines. I have listed a very simple example below. If anyone has experienced this I would be really appreciate any support in resolving this issue.
Simple example of issue:
When I use the following code it works fine.
Sheets("Sheet1").Select
Range("B3").Select
When I combine them I get a "1004" error
Sheets("Sheet1").Range("B3").Select
I checked the reference/document library and nothing appears to have changed in here. It has to be something simple but I just can't put my finger on it.
If you absolutely must do it in a single line of code then swap the Select for an Application.GoTo which accepts both worksheet and cell range.
application.goto range("Sheet1!B3")
However, it is almost never necessary (and most often counter-productive) to use the Range .Select method to reference a cell or cells to work on. See How to avoid using Select in Excel VBA macros for methods on getting away from relying on select and activate to accomplish your goals.
You already have your answer:
first Select the worksheet
the Select a range on that worksheet
Your code will work if you happen to be on Sheet1 when it is run, but will fail if you are not on Sheet1. In my opinion VBA is kind of dumb with regard to this issue.

Utilise ShowDataForm Excel but hide data

I have attempted the solution previously posted
https://stackoverflow.com/a/31642837/6463950
but whilst this code works nicely it doesn't get round the issue of wanting to have the database hidden from the user view. Has anyone determined a way to do this?
I am using the following code. If I hide the worksheet or hide the columns on TimeCapture then I get a runtime error '1004'
Sub OrderEntry()
Sheets("TimeCapture").Select
Range("a1").CurrentRegion.Name = "database"
ActiveSheet.ShowDataForm
End Sub
There is no need to select or active the sheet. You can even have the worksheet hidden.
Use:
Sheets("TimeCapture").ShowDataForm

Can I add validation to Excel's ShowDataForm?

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 :(

Resources