Hi- Still learning VBA...
I created a user form that links to the specific account that is being searched.
The user form is used to update or add the customer interactions/contact info ect... for that specific account.
The code I have below works...but it is extremely slow.
Any suggestions on how to improve the code would be very much appreciated.
Thank you
I created a user form that links to the specific account that is being searched.
The user form is used to update or add the customer interactions/contact info ect... for that specific account.
The code I have below works...but it is extremely slow.
Any suggestions on how to improve the code would be very much appreciated.
Thank you
VBA Code:
Private Sub UserForm_Initialize()
Dim account_number As String
account_number = Worksheets("SEARCH").Range("E11")
lastrow = Worksheets("Past_Communications").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Worksheets("Past_Communications").Cells(i, 1).Value = account_number Then
Notes.Text = Worksheets("Past_Communications").Cells(i, 3).Value
CI.Text = Worksheets("Past_Communications").Cells(i, 4).Value
TS.Text = Worksheets("Past_Communications").Cells(i, 5).Value
SR.Text = Worksheets("Past_Communications").Cells(i, 6).Value
End If
Next
End Sub
Private Sub CommandButton1_Click()
Dim account_number As String
account_number = Worksheets("SEARCH").Range("E11")
lastrow = Worksheets("Past_Communications").Cells(Rows.Count, 1).End(xlUp).Row
Dim MIU As String
MIU = Worksheets("SEARCH").Range("E13")
Dim wsh As Worksheet
Set wsh = ThisWorkbook.Worksheets("Past_Communications")
Set tbl = wsh.ListObjects("Past_Comm")
Dim addRow As ListRow
Set addRow = tbl.ListRows.Add
For i = 2 To lastrow
If Worksheets("Past_Communications").Cells(i, 1).Value = account_number Then
Worksheets("Past_Communications").Cells(i, 3).Value = Notes.Text
Worksheets("Past_Communications").Cells(i, 4).Value = CI.Text
Worksheets("Past_Communications").Cells(i, 5).Value = TS.Text
Worksheets("Past_Communications").Cells(i, 6).Value = SR.Text
Else
With addRow
.Range(1) = account_number
.Range(2) = MIU
.Range(3) = Notes.Text
.Range(4) = CI.Text
.Range(5) = TS.Text
.Range(6) = SR.Text
End With
End If
Next
MsgBox "Saved", vbDefaultButton1, "Saved"
End Sub