简体   繁体   中英

Excel Data entry forms in VBA

I am very new to VBA and have been searching to try to figure this out but with no luck.

I am trying to make a form that pops up and has a bunch of different fields to enter and then when the form is submitted, the information is input into separate, specific cells. Also, once the information is input into the cells, it needs to be printed for our records. One last thing to add is that I need some of the fields to disappear if they are empty on the form so that they do not print.

I have a lot of fields for this and all that I have found is how to insert into a new row. If this can be done it would help me out a LOT. If anyone can point me in the right direction then I may be able to figure some out on my own I am fairly literate in HTML so I am able to do some coding.

The fields I have to enter:

Deposited By:
Number of Deposits:
Total Checks:
Electronic Deposit Number:
Electronic Deposit Number:
Manual Deposit Number:
Deposit Amount:
Deposit Amount:
Deposit Amount:
Houston Depos:
Dallas Depos:
Austin Depos:
Houston Video:
Dallas Video:
Austin Video:
Houston Records:

I will also need to add a button or make the form popup whenever the spreadsheet is opened so that the information can be entered but I believe that may be a little easier to figure out. Along with pre-filling the form with the information already on the page so that it can be edited.

I'll try to answer a few of your questions that you had so hopefully you can write some of your own code:

Form popup whenever the spreadsheet is opened (Placed in the ThisWorkbook code):

Private Sub Workbook_Open()
    UserForm1.Show
End Sub

You can also add a button in the Worksheet and assign it a macro which uses UserForm1.Show.

For the pre-filling the form with information from the sheet use commands like this (Placed in your UserForm code:

Private Sub UserForm_Initialize()
    txtDepositedBy.Text = Sheets("Sheet1").Range("A2")
End Sub

To print your sheets use the Sheets.PrintOut Method:

ActiveSheet.PrintOut
'or
Sheets("Sheet3").PrintOut

It has these inputs:

.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas)

To take your inputs from text boxes and other elements, you can use commands like these:

ActiveSheet.Range("A1").Value = TextBox1.Text
'or
Sheets("Sheet3").Range("B2").Value = ComboBox1.Text

This should cover a lot of your questions. If you have anymore just let me know and I'll add to the post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM