VBA Userform makes excel unresponsive. help!

sparkyyc

New Member
Joined
May 28, 2015
Messages
2
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
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Watch MrExcel Video

Forum statistics

Threads
1,127,531
Messages
5,625,368
Members
416,096
Latest member
forevans

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
Top