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
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