Hello! I'm extremely new to VBA and need help on my code. I wanted to create a userform that was a data input form, it's for a contact list and this makes it easier for my coworkers to add the clients information. It works some of the time but other times it just freezes excel and it becomes unresponsive when I hit Add which should add the info to the list. Any way I can fix that? Also I know it's not a pretty code since I just learned about VBA a few days ago haha so if anyone has suggestions on making it better just let me know! Also this is on excel 2011 Mac.
Private Sub cmdAdd_Click()
Dim emptyRow As Long
'Activate Workbook
Workbooks("Client List With Emails_Form.xlsm").Activate
'Activate Worksheet
Workbooks("Client List With Emails_Form.xlsm").Sheets("ContactList").Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
Cells(emptyRow, 1).Value = txtFirstName.Value
Cells(emptyRow, 2).Value = txtLastName.Value
Cells(emptyRow, 3).Value = cboType.Value
Cells(emptyRow, 4).Value = txtCompany.Value
Cells(emptyRow, 5).Value = txtAddress.Value
Cells(emptyRow, 6).Value = txtCity.Value
Cells(emptyRow, 7).Value = txtState.Value
Cells(emptyRow, 8).Value = txtZipcode.Value
Cells(emptyRow, 9).Value = txtEmail.Value
Cells(emptyRow, 10).Value = txtPhoneNumber.Value
Cells(emptyRow, 11).Value = txtPhone2.Value
Cells(emptyRow, 12).Value = cboStatus.Value
Cells(emptyRow, 13).Value = cboPriority.Value
Cells(emptyRow, 14).Value = cboGift.Value
End Sub
Private Sub cmdClear_Click()
Call UserForm_Initialize
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
'Empty txtFirstName
txtFirstName.Value = ""
'Empty txtLastName
txtFirstName.Value = ""
'Empty txtCompany
txtCompany.Value = ""
'Empty txtAddress
txtAddress.Value = ""
'Empty txtCity
txtCity.Value = ""
'Empty txtState
txtState.Value = ""
'Empty txtZipcode
txtZipcode.Value = ""
'Empty txtEmail
txtEmail.Value = ""
'Empty txtPhoneNumber
txtPhoneNumber.Value = ""
'Set Focus on txtFirstName
txtFirstName.SetFocus
'Empty cboType
cboType.Clear
'Fill cboType
With cboType
.AddItem "Client"
.AddItem "Media"
.AddItem "Vendor"
End With
'Empty txtPhone2
txtPhone2.Value = ""
'Empty cboStatus
cboStatus.Value = ""
'Fill cboStatus
With cboStatus
.AddItem "Active"
.AddItem "Inactive"
.AddItem "Potential"
End With
'Empty cboPriority
cboPriority.Value = ""
'Fill cboPriority
With cboPriority
.AddItem "Primary"
.AddItem "Secondary"
.AddItem "Other"
End With
'Empty cboGift
cboGift.Value = ""
'Fill cboGift
With cboGift
.AddItem "Gift"
.AddItem "Card"
.AddItem "None"
.AddItem "Other/TBD"
End With
Label1.Font.Size = 12
Label2.Font.Size = 12
Label3.Font.Size = 12
Label4.Font.Size = 12
Label5.Font.Size = 12
Label6.Font.Size = 12
Label7.Font.Size = 12
Label8.Font.Size = 12
Label9.Font.Size = 12
Label10.Font.Size = 12
Label11.Font.Size = 12
Label12.Font.Size = 12
Label13.Font.Size = 12
Label14.Font.Size = 12
cmdAdd.Font.Size = 12
cmdClear.Font.Size = 12
cmdClose.Font.Size = 12
End Sub
Private Sub cmdAdd_Click()
Dim emptyRow As Long
'Activate Workbook
Workbooks("Client List With Emails_Form.xlsm").Activate
'Activate Worksheet
Workbooks("Client List With Emails_Form.xlsm").Sheets("ContactList").Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
Cells(emptyRow, 1).Value = txtFirstName.Value
Cells(emptyRow, 2).Value = txtLastName.Value
Cells(emptyRow, 3).Value = cboType.Value
Cells(emptyRow, 4).Value = txtCompany.Value
Cells(emptyRow, 5).Value = txtAddress.Value
Cells(emptyRow, 6).Value = txtCity.Value
Cells(emptyRow, 7).Value = txtState.Value
Cells(emptyRow, 8).Value = txtZipcode.Value
Cells(emptyRow, 9).Value = txtEmail.Value
Cells(emptyRow, 10).Value = txtPhoneNumber.Value
Cells(emptyRow, 11).Value = txtPhone2.Value
Cells(emptyRow, 12).Value = cboStatus.Value
Cells(emptyRow, 13).Value = cboPriority.Value
Cells(emptyRow, 14).Value = cboGift.Value
End Sub
Private Sub cmdClear_Click()
Call UserForm_Initialize
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
'Empty txtFirstName
txtFirstName.Value = ""
'Empty txtLastName
txtFirstName.Value = ""
'Empty txtCompany
txtCompany.Value = ""
'Empty txtAddress
txtAddress.Value = ""
'Empty txtCity
txtCity.Value = ""
'Empty txtState
txtState.Value = ""
'Empty txtZipcode
txtZipcode.Value = ""
'Empty txtEmail
txtEmail.Value = ""
'Empty txtPhoneNumber
txtPhoneNumber.Value = ""
'Set Focus on txtFirstName
txtFirstName.SetFocus
'Empty cboType
cboType.Clear
'Fill cboType
With cboType
.AddItem "Client"
.AddItem "Media"
.AddItem "Vendor"
End With
'Empty txtPhone2
txtPhone2.Value = ""
'Empty cboStatus
cboStatus.Value = ""
'Fill cboStatus
With cboStatus
.AddItem "Active"
.AddItem "Inactive"
.AddItem "Potential"
End With
'Empty cboPriority
cboPriority.Value = ""
'Fill cboPriority
With cboPriority
.AddItem "Primary"
.AddItem "Secondary"
.AddItem "Other"
End With
'Empty cboGift
cboGift.Value = ""
'Fill cboGift
With cboGift
.AddItem "Gift"
.AddItem "Card"
.AddItem "None"
.AddItem "Other/TBD"
End With
Label1.Font.Size = 12
Label2.Font.Size = 12
Label3.Font.Size = 12
Label4.Font.Size = 12
Label5.Font.Size = 12
Label6.Font.Size = 12
Label7.Font.Size = 12
Label8.Font.Size = 12
Label9.Font.Size = 12
Label10.Font.Size = 12
Label11.Font.Size = 12
Label12.Font.Size = 12
Label13.Font.Size = 12
Label14.Font.Size = 12
cmdAdd.Font.Size = 12
cmdClear.Font.Size = 12
cmdClose.Font.Size = 12
End Sub