Excel UserForm Data Entry (VBA) #6 - Insert Makro Button
Learn how to create (insert) macro button to worksheet to show UserForm in Excel VBA.
The code used in this video:
Private Sub btnCancel_Click()
Unload Me
End Sub
Private Sub btnOK_Click()
Dim ws As Worksheet
Set ws = Worksheets("Customers")
Dim newRow As Long
newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
ws.Cells(newRow, 1).Value = Me.txtFirstName.Value
ws.Cells(newRow, 2).Value = Me.txtSurname.Value
ws.Cells(newRow, 3).Value = Me.cbCountries.Value
If obMale.Value = True Then
ws.Cells(newRow, 4).Value = "Male"
Else
ws.Cells(newRow, 4).Value = "Female"
End If
If Me.cbPost.Value = True Then
ws.Cells(newRow, 5).Value = "Yes"
Else
ws.Cells(newRow, 5).Value = "No"
End If
If Me.cbTelephone.Value = True Then
ws.Cells(newRow, 6).Value = "Yes"
Else
ws.Cells(newRow, 6).Value = "No"
End If
For i = 0 To Me.lbDays.ListCount - 1
If Me.lbDays.Selected(i) Then
ws.Cells(newRow, 7).Value = ws.Cells(newRow, 7).Value + Me.lbDays.List(i) + " "
End If
Next i
End Sub
Private Sub UserForm_Initialize()
With cbCountries
.AddItem "Canada"
.AddItem "New Zealand"
End With
With Me.lbDays
.AddItem "Monday"
.AddItem "Tuesday"
.AddItem "Wednesday"
End With
End Sub
And that one below goes into Module1:
Sub Button1_Click()
ufCustomers.Show
End Sub
Видео Excel UserForm Data Entry (VBA) #6 - Insert Makro Button канала InAnOffice
The code used in this video:
Private Sub btnCancel_Click()
Unload Me
End Sub
Private Sub btnOK_Click()
Dim ws As Worksheet
Set ws = Worksheets("Customers")
Dim newRow As Long
newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
ws.Cells(newRow, 1).Value = Me.txtFirstName.Value
ws.Cells(newRow, 2).Value = Me.txtSurname.Value
ws.Cells(newRow, 3).Value = Me.cbCountries.Value
If obMale.Value = True Then
ws.Cells(newRow, 4).Value = "Male"
Else
ws.Cells(newRow, 4).Value = "Female"
End If
If Me.cbPost.Value = True Then
ws.Cells(newRow, 5).Value = "Yes"
Else
ws.Cells(newRow, 5).Value = "No"
End If
If Me.cbTelephone.Value = True Then
ws.Cells(newRow, 6).Value = "Yes"
Else
ws.Cells(newRow, 6).Value = "No"
End If
For i = 0 To Me.lbDays.ListCount - 1
If Me.lbDays.Selected(i) Then
ws.Cells(newRow, 7).Value = ws.Cells(newRow, 7).Value + Me.lbDays.List(i) + " "
End If
Next i
End Sub
Private Sub UserForm_Initialize()
With cbCountries
.AddItem "Canada"
.AddItem "New Zealand"
End With
With Me.lbDays
.AddItem "Monday"
.AddItem "Tuesday"
.AddItem "Wednesday"
End With
End Sub
And that one below goes into Module1:
Sub Button1_Click()
ufCustomers.Show
End Sub
Видео Excel UserForm Data Entry (VBA) #6 - Insert Makro Button канала InAnOffice
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Excel VBA Application InputBox #2 - Adding title](https://i.ytimg.com/vi/7Lhta91CZtU/default.jpg)
![Excel VBA Tutorial for Beginners #4 - How to view the VBA code](https://i.ytimg.com/vi/iy78U3FF830/default.jpg)
![Excel Tips and Tricks #5 How to Delete Duplicates](https://i.ytimg.com/vi/qV5J6xS73Wo/default.jpg)
![Excel Tips and Tricks #27 How to Copy Visible Cells Only](https://i.ytimg.com/vi/HSHv3yRazeM/default.jpg)
![Excel Tips and Tricks #63 How to Fill Empty Cells with 0](https://i.ytimg.com/vi/juhFWHY5-JA/default.jpg)
![Excel VBa - How To Create An Excel Userform To Add Edit And Delete](https://i.ytimg.com/vi/uTwX4ejN7SQ/default.jpg)
![Excel VBA Tutorial for Beginners #1 - How to enable VBA](https://i.ytimg.com/vi/NISGh4-ZBFQ/default.jpg)
![Excel Notes #2 How to Jump Between Notes](https://i.ytimg.com/vi/vqMms7QsTbg/default.jpg)
![Excel Tips and Tricks #73 Progress Circle Chart in Excel](https://i.ytimg.com/vi/wsexwVfDmvc/default.jpg)
![Excel Tips and Tricks #75 How to Add Currency Symbol Automatically in Excel](https://i.ytimg.com/vi/6DgT7BXhgYk/default.jpg)
![Excel VBA - How to Assign a Macro to the Quick Access Toolbar](https://i.ytimg.com/vi/fRTrCo5cxK0/default.jpg)
![Excel Tips and Tricks #76 How to make Excel Speak](https://i.ytimg.com/vi/Vl2CKto3oHk/default.jpg)
![Excel VBA UserForm Listbox with Option Buttons](https://i.ytimg.com/vi/4N684F037jc/default.jpg)
![Excel Tips and Tricks #52 Hard Code an Array in a Vlookup Formula](https://i.ytimg.com/vi/pYnmcWBhwYA/default.jpg)
![Excel VBA UserForm How to Add Radio Button/Checkbox Controls to List Box](https://i.ytimg.com/vi/k7TdOsqsV2Q/default.jpg)
![Excel Tips and Tricks #3 How to Add Multiple Lines to Text within Cell](https://i.ytimg.com/vi/ujRlOfuYiG0/default.jpg)
![Excel VBA Tutorial for Beginners #10 Check If Cell Is Empty](https://i.ytimg.com/vi/lNTQZ2rClHg/default.jpg)
![Excel VBA UserForm Combobox with Option Buttons](https://i.ytimg.com/vi/lEWwXAbx0Z8/default.jpg)
![Excel Tips and Tricks #25 How to group rows and columns automatically (outline)](https://i.ytimg.com/vi/SV4fpuZBEvw/default.jpg)
![Excel Tips and Tricks #15 How to Show Error Alert When User Enters Invalid Data](https://i.ytimg.com/vi/WNCRpJnCjyU/default.jpg)
![Excel VBA UserForm Combobox Tip Text (ControlTipText)](https://i.ytimg.com/vi/sWdTmcHaWBU/default.jpg)