Userform code works to add data to worksheet, but is TOO SLOW

cpaggi01

New Member
Joined
Nov 17, 2014
Messages
1
Hi there, I have a userform to add and update a project database. The database is around 200 columns long (project info) by about 200 rows deep (individual projects). I have a userform to help enter in the project data that then updates the "master database" sheet when a command button is pressed. The code that I have works, but it takes almost 20 seconds to update the worksheet with the information that was entered into the 200 or so userform textboxes. Here's my code for the update command:

Private Sub cmbPJTID_Afterupdate()
Dim findvalue
Dim i As Integer
Set findvalue = Sheet1.Range("A:A").Find(Me.cmbPJTID.Value)
cNum = 200
For X = 1 To cNum
Me.Controls("tb" & X).Value = findvalue
Set findvalue = findvalue.Offset(0, 1)
Next
End Sub




Private Sub UpdateDB_Click()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim nextrow As Range
Dim n As Long
cNum = 200
If Me.OptionButton1.Value = True Then
Set nextrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For X = 1 To cNum
nextrow = Me.Controls("tb" & X).Value
Set nextrow = nextrow.Offset(0, 1)
Next
MsgBox "The project " & Me.tb1.Value & " has been added to the project database!"
ElseIf Me.OptionButton2.Value = True Then
If IsError(Application.Match(cmbPJTID.Value, Range("pjt_rng"), 0)) Then
MsgBox "Project ID specified does not match any existing projects. Please verify that the Project ID is correct. To add a new project, please check 'Add New Project'"
Else
n = Application.Match(Me.cmbPJTID.Value, Worksheets("Master Database").Range("A:A"), 0)
For X = 1 To cNum
Worksheets("Master Database").Cells(n, X).Value = Me.Controls("tb" & X)
Next X
MsgBox "The project " & Me.tb1.Value & " has been added to the project database!"
End If
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub


A little background: The userform pops up and you choose option button 1 or 2 to create a new project or update an existing project respectively. If you add a new project, the code finds the last row and enters the project info in below that...if you update an existing, it finds the project you are referencing in a listbox, autofills the textboxes in the userform with the data from the worksheet, and updates the respective row. Right now, the code updates EACH cell in the specified row when the command button "UpdateDB" is pressed. Is there another way to code this to speed it up?

I'm confused also because when I update an existing project, the textboxes in the userform (all 200 of them) update instantaneously with the information in the worksheet cells....but when trying to update the cells from the contents of the textbox, it seems to take forever....does that make sense? (Cells to textbox is quick, while textbox to cells takes forever) I have been struggling with this for days!!! PLEASE HELP!!

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,216,225
Messages
6,129,603
Members
449,520
Latest member
TBFrieds

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