Add "Open Form" to existing macro

cookeetree

Board Regular
Joined
Mar 2, 2015
Messages
52
G'day Excel Gods,

I have an existing macro that creates a blank line at the top of my data table. I've just added a data entry form and want this to open when the macro runs. How do I get this to happen? I've tried adding "ActiveSheet.ShowDataForm" to the end of my existing macro, but this errors and I get this:

Run-time error '1004':
ShowDataForm method of Worksheet class failed


How can I make this work? Alternatively, how can I get my form to create the new line at the top of the sheet instead of the bottom???

Any help you could provide would be greatly appreciated.

Cheers, Jason.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I need to go through all the code in the userform to see which line of all the code has the problem.

Can you share your file?

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
I need to go through all the code in the userform to see which line of all the code has the problem.

Can you share your file?

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
I can't share the file, but here's the macro. Everything but the last line is what I was using to create a new line at the top. The last line was added to open the form, but this is where the wheels fall off...

Sub New_Lab_Sample_Form()
'
' New_Lab_Sample_Form Macro
'

'
Range("A3:M3").Select
Selection.Copy
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Selection.ClearContents
Range("B3").Select
ActiveCell.FormulaR1C1 = "=R[1]C+1"
Range("A3").Select
ActiveSheet.ShowDataForm

End Sub
 
Upvote 0
Sub New_Lab_Sample_Form()
' New_Lab_Sample_Form Macro
Range("A3:M3").Select
Selection.Copy
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Selection.ClearContents
Range("B3").Select
ActiveCell.FormulaR1C1 = "=R[1]C+1"
Range("A3").Select
ActiveSheet.ShowDataForm
End Sub

Works for me.
In row 2 from A2 to M2 you must put the headings, preferably with capital letters, so that Excel identifies it as a form. ;)
 
Upvote 0
Works for me.
In row 2 from A2 to M2 you must put the headings, preferably with capital letters, so that Excel identifies it as a form. ;)
Row 2 already has this.

I can run the macro without the "open form" line and then manually open the form and this works fine. It's only when I try to open the form via the macro that it fails.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top